Daniel Danielecki
Daniel Danielecki

Reputation: 10590

GitLab CI: avoid duplication of skip-ci for each job

Currently, I'm duplicating the information about skip-ci in every single job, like so

job1:
  except:
    variables:
      - $CI_COMMIT_MESSAGE =~ /skip-ci/
    ...
job2:
  except:
    variables:
      - $CI_COMMIT_MESSAGE =~ /skip-ci/
    ...
job3:
  except:
    variables:
      - $CI_COMMIT_MESSAGE =~ /skip-ci/
    ...

Is there any way to write it only once and it'd apply for all the jobs?

Upvotes: 7

Views: 8586

Answers (3)

David Hönig
David Hönig

Reputation: 71

The full functionality can be achieved when you allow all posibilities. You typically include [ci-skip] or [skip-ci] in your commit message, it will skip automatically. Note that [SkIp cI] will work too..

From GitLab source code

SKIP_PATTERN = /\[(ci[ _-]skip|skip[ _-]ci)\]/i

https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/pipeline/chain/skip.rb#L10

Upvotes: 0

Simon Leiß
Simon Leiß

Reputation: 544

In case you are not relying exactly on skip-ci, Gitlab already includes logic for this: When a commit message contains [skip ci] or [ci skip], the pipeline is skipped, according to the docs.

Upvotes: 12

DV82XL
DV82XL

Reputation: 6659

There are two ways to do this in GitLab:

Job Inheritance

This is the recommended approach, since it's more readable than YAML anchors and you can extend from multiple jobs if you need to. In the following example, the period in front of the job name causes GitLab to hide the job so the template job doesn't get executed on its own.

.skip-ci:
  except:
    variables:
      - $CI_COMMIT_MESSAGE =~ /skip-ci/

job1:
  extends: .skip-ci
    ...
job2:
  extends: .skip-ci
    ...
job3:
  extends: .skip-ci
    ...

YAML Anchors

I've included this approach for completeness, but generally it's almost always better to use extends.

.skip-ci: &skip-ci
  except:
    variables:
      - $CI_COMMIT_MESSAGE =~ /skip-ci/

job1:
  <<: *skip-ci
    ...
job2:
  <<: *skip-ci
    ...
job3:
  <<: *skip-ci
    ...

Upvotes: 5

Related Questions