GitLab-CI Keywords - Things you'll find in .gitlab-ci.yml

mail

tags

mail

needs

needs creates dependencies between jobs in a pipeline so that jobs run as soon as their dependencies are met, regardless of the pipeline's stagesstages configuration.
You can even configure a pipeline with no stages defined (effectively one large stage) and jobs still run in the proper order.
mail

artifacts

artifacts
mail

when

when

  • is a job keyword
  • the word when has been somewhat misleading to me, since
    • this directive doesn't explicitly define conditions to run a job
    • instead, it defines a job type, which is one of (i.e. the corresponding job runs...) :
      • on_success / on_failure of previous jobs
      • always / never
      • manually (as a manual job)
  • defaults to when: on_success
  • example :
    myJob:
      stage: 
      
      when: keyword

rules:when

  • like when, defines the job type BUT has some differences :
    • it has more / different job type keywords
    • it must be combined with one of :
      • changes
      • if
      • exists
      so that setting the job type becomes conditional
      omitting changes / if / exists
      • is actually setting no condition
      • is evaluated as true and the corresponding rule always matches
  • example :
    job1:
      rules:
        - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
        - if: $CI_COMMIT_REF_NAME =~ /feature/
          when: delayed
        - when: manual
      script:
        - echo
mail

changes

changes: pathSpec

  • pathSpec can be
    • an explicit list of files
    • a single entry with wildcards
  • there is a logical OR within files listed by pathSpec
  • if any file matching pathSpec has changed, add the job to the pipeline
  • in case of empty pathSpec, changes evaluates to true for any change in the repository
mail

rules

rules: conditions

  • if: statement
    • if statement is true, add the job to the pipeline
    • if statement is true but it's combined with when: never : do not add the job to the pipeline
    • if statement is false, check the next rules item (if any)
  • changes: pathSpec
  • exists: pathSpec
    • if any file matching pathSpec exists, add the job to the pipeline
  • when: keyword

Subtlety about adding a job to a pipeline / NOT adding a job to a pipeline / running a job :

  • when conditions match, a job is added to a pipeline
  • once a job has been added to a pipeline, it will be run
  • but when conditions don't match, the job is not added to the pipeline
    • which doesn't mean it forbids this job execution : it's just that conditions of the current rule are not met now to add this job to the pipeline
    • but further rules may match and add it