6

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?

DV82XL
  • 5,350
  • 5
  • 30
  • 59
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94

2 Answers2

8

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.

Simon Leiß
  • 474
  • 3
  • 10
  • Interesting, wasn't aware of. Definitely will check it out! PS. Would be good to link the exact hyperlink https://docs.gitlab.com/ee/ci/yaml/#skip-pipeline, because the GitLab's docs is soo huge. – Daniel Danielecki Feb 02 '21 at 08:28
  • 1
    Actually, the link is already set to the one you proposed (you can see it when hovering over the link), but for me (and probably also you), the position of the page is a bit off (like half a page to the bottom). Does also happens when clicking on the link you posted, at least for me. – Simon Leiß Feb 02 '21 at 08:52
  • For me it doesn't happen, checked `Opera` and `Safari`. – Daniel Danielecki Feb 02 '21 at 10:09
  • This indeed works best, but the question was slightly different therefore left the original answer accepted :) Thanks tho, will use the `[skip ci]` thing. It's not written in the docs, but `[skip-ci]` works too! – Daniel Danielecki Feb 14 '21 at 11:06
  • 1
    Docs link has changed again: https://docs.gitlab.com/ee/ci/pipelines/index.html#skip-a-pipeline – JinnKo Nov 30 '21 at 21:18
  • @JinnKo Thanks, I changed the link in the answer! – Simon Leiß Nov 30 '21 at 23:38
4

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
    ...
DV82XL
  • 5,350
  • 5
  • 30
  • 59