简体   繁体   中英

Run a pre job before GitLab pipeline

I want to run a job each time a new pipeline gets triggered. It's a kind of preparation job which should always be executed before every other job defined inside the .gitlab-ci.yml

For Example

stages:
  - build
  - test

my-prep-job:
  stage: .pre
  script:
    # this is the job I want to run every time a pipeline gets triggered before other jobs
    # also it will have an artifact that I want to use in rest of the job
  ...
  artifacts:
    ...

Build:
  stage: build
  ...

Test:
  stage: test
  ....

Please, let me know if this is possible or if there is other way around.

Thanks in Advance...

Edit

I did try adding .pre under stages . Thing is I had to rewrite the rules and add it to my-prep-job stages as well.

stages:
  - .pre # I did add it over here
  - build
  - test

Also I had to add the rules to this stage as well so that it would not run on it's own on just a normal commit/push.

Is there any possibility to extend ".pre" stage of GitLab pipeline?

You could use !reference tags to include certain keyword sections. For example:

.pre
  script:
    - echo from pre

example:
  stage: test
  script:
    - !reference [.pre, script]
    - ...

Will include the script part of .pre into the example job.

You can use !reference for most of the job keywords like artifacts or rules

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM