Select While To Run Jobs

By | March 22, 2022

Specify when jobs run with regulations guidelines examples Run jobs for scheduled pipelinesComplex regulationsAvoid replica pipelinesCommon if clauses for guidelinesVariables in regulations:adjustmentsReuse rules in exclusive jobsSpecify when jobs run with best and besides simplest:refs / besides:refs examplesmost effective: variables / except: variables examplesmost effective:modifications / besides:adjustments examples Use handiest:modifications with merge request pipelinesCombine a couple of keywords with only or exceptCreate a process that must be run manually Types of manual jobsRun a manual taskProtect guide jobsRun a job after a postponeParallelize large jobs Run a one-dimensional matrix of parallel jobsRun a matrix of parallel trigger jobsSelect one of a kind runner tags for each parallel matrix task Fetch artifacts from a parallel:matrix jobUse predefined CI/CD variables to run jobs most effective in particular pipeline typesRegular expressions handiest / except regex syntaxCI/CD variable expressions Compare a variable to a stringComparevariablesCheck if a variable is undefinedCheck if a variable is emptyCheck if a variable existsCompare a variable to a regex sampleJoin variable expressions together with && or collectively with parenthesesTroubleshooting Jobs or pipelines run abruptly whilst the use of adjustments:You are not allowed to down load code from this venture. errors message

When a new pipeline starts offevolved, GitLab tests the pipeline configuration to determinewhich jobs need to run in that pipeline. You can configure jobs to run relying onthe popularity of variables, the pipeline kind, and so forth.

To configure a process to be blanketed or excluded from sure pipelines, you could use:guidelinessimplestbesides

Use needs to configure a process to run as quickly as theearlier jobs it relies upon on finish going for walks.Specify while jobs run with guidelines

Use rules to consist of or exclude jobs in pipelines.

Rules are evaluated in order till the first match. When a healthy is observed, the jobis either covered or excluded from the pipeline, relying at the configuration.See the guidelines reference for more information.

Future keyword enhancements are being discussed in our epic for enhancing policies,wherein anybody can upload recommendations or requests.regulations examples

The following example uses if to outline that the job runs in simplest two particular instances:job:script: echo “Hello, Rules!”rules:- if: ‘$CI_PIPELINE_SOURCE == “merge_request_event”‘while: manualallow_failure: proper- if: ‘$CI_PIPELINE_SOURCE == “agenda”‘If the pipeline is for a merge request, the first rule fits, and the jobis introduced to the merge request pipelinewith attributes of:when: guide (guide job)allow_failure: true (the pipeline maintains walking despite the fact that the manual task isn’t always run)If the pipeline isn’t for a merge request, the first rule doesn’t match, and thesecond rule is evaluated.If the pipeline is a scheduled pipeline, the second rule fits, and the jobis introduced to the scheduled pipeline. No attributes have been defined, so it’s far addedwith:whilst: on_success (default)allow_failure: false (default)In all different instances, no rules in shape, so the activity isn’t added to another pipeline.

Alternatively, you can define a fixed of guidelines to exclude jobs in some instances, butrun them in all different cases:job:script: echo “Hello, Rules!”policies:- if: ‘$CI_PIPELINE_SOURCE == “merge_request_event”‘whilst: in no way- if: ‘$CI_PIPELINE_SOURCE == “time table”‘when: in no way- whilst: on_successIf the pipeline is for a merge request, the activity isn’t always added to the pipeline.If the pipeline is a scheduled pipeline, the job isn’t always introduced to the pipeline.In all different instances, the task is added to the pipeline, with while: on_success.caution

If you use a when clause as the very last rule (now not consisting of whilst: by no means), twosimultaneous pipelines can also begin. Both push pipelines and merge request pipelines canbe triggered by using the equal occasion (a push to the supply branch for an open merge request).See the way to save you duplicate pipelinesfor extra info.Run jobs for scheduled pipelines

To configure a task to be carried out handiest whilst the pipeline has beenscheduled, use the guidelines keyword.

In this situation, make world runs in scheduled pipelines, and make buildruns in department and tag pipelines:activity:on-time table:policies:- if: $CI_PIPELINE_SOURCE == “schedule”script:- make worldjob:guidelines:- if: $CI_PIPELINE_SOURCE == “push”script:- make buildComplex regulations

You can use all regulations keywords, like if, modifications, and exists, inside the samerule. The rule evaluates to real most effective while all protected key phrases evaluate to authentic.

For example:docker construct:script: docker construct -t my-picture:$CI_COMMIT_REF_SLUG .policies:- if: ‘$VAR == “string cost”‘adjustments:# Include the activity and set to when:manual if any of the comply with paths suit a changed record.- Dockerfile- docker/scripts/*while: manualallow_failure: true

If the Dockerfile document or any document in /docker/scripts has modified and $VAR == “string price”,then the process runs manually and is authorizedconstruct greater complex variable expressions.Introduced in GitLab 13.three:job1:script:- echo This rule makes use of parentheses.policiesbroaden”) && $MY_VARIABLEcaution

Before GitLab thirteen.three,guidelines that use each and && may also evaluate with an unexpected order of operations.Avoid replica pipelines

If a process uses guidelines, a unmarried motion, like pushing a commit to a branch, can triggermultiple pipelines. You don’t have to explicitly configure rules for more than one typesof pipeline to trigger them by accident.

Some configurations which have the capacity to reason replica pipelines motive apipeline warning to be displayed.Introduced in GitLab thirteen.3.

For example:task:script: echo “This job creates double pipelines!”regulations:- if: ‘$CUSTOM_VARIABLE == “false”‘whilst: in no way- when: always

This job does no longer run whilst $CUSTOM_VARIABLE is false, but it does run in allother pipelines, such as each push (department) and merge request pipelines. Withthis configuration, each push to an open merge request’s supply branchcauses duplicated pipelines.

To keep away from replica pipelines, you can:Use workflow to specify which kinds of pipelinescan run.

Rewrite the guidelines to run the job handiest in very particular instances,and keep away from a final while rule:process:script: echo “This process does NOT create double pipelines!”policies:- if: ‘$CUSTOM_VARIABLE == “authentic” && $CI_PIPELINE_SOURCE == “merge_request_event”‘

You can also avoid duplicate pipelines by way of converting the task policies to keep away from both push (branch)pipelines or merge request pipelines. However, in case you use a – while: always rule withoutworkflow: policies, GitLab nevertheless displays a pipeline warning.

For example, the subsequent does now not cause double pipelines, but isn’t always recommendedwithout workflow: policies:activity:script: echo “This activity does NOT create double pipelines!”regulations:- if: ‘$CI_PIPELINE_SOURCE == “push”‘while: by no means- while: continually

You have to now not consist of each push and merge request pipelines within the equal job withoutworkflow:guidelines that save you replica pipelines:process:script: echo “This task creates double pipelines!”regulations:- if: ‘$CI_PIPELINE_SOURCE == “push”‘- if: ‘$CI_PIPELINE_SOURCE == “merge_request_event”‘

Also, do no longer blend only/besides jobs with guidelines jobs in the same pipeline.It won’t purpose YAML errors, however the special default behaviors of most effective/exceptand regulations can reason problems that are hard to troubleshoot:task-with-no-regulations:script: echo “This task runs in department pipelines.”activity-with-regulations:script: echo “This job runs in merge request pipelines.”policies:- if: ‘$CI_PIPELINE_SOURCE == “merge_request_event”‘

For each change driven to the department, duplicate pipelines run. Onebranch pipeline runs a unmarried job (process-with-no-regulations), and one merge request pipelineruns the alternative task (process-with-policies). Jobs without a policies defaultto besides: merge_requests, so process-with-no-rulesruns in all cases besides merge requests.Common if clauses for guidelines

For behavior much like the best/except keywords, you cancheck the value of the $CI_PIPELINE_SOURCE variable:

Leave a Reply

Your email address will not be published.