Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instruct gitlab ci to run only certain stages for a commit

Just like git push -o ci.skip can be used to skip all stages, is it possible to also just as easily specify a whitelist of stages to run while pushing?

Currently I have to manually go to gitlab UI after a push and skip the stages that I don't want running. I also have to track stage dependencies manually while doing this.

Can this be done more easily?

like image 954
Peeyush Kushwaha Avatar asked May 26 '26 10:05

Peeyush Kushwaha


1 Answers

You can set CICD variables with git push options. Therefore, you can use such variables to set whether a job runs or not using only:variables/except:variables or rules:

For example:

my_job:
  rules:
    - if: $MY_VARIABLE_NEVER
      when: never
    - if: $MY_VARIABLE_ALWAYS
      when: always
    - when: on_success
  # ...

Then you can use the push option to set the variables in your rules:

# excludes my_job from the pipeline
git push -o ci.variable="MY_VARIABLE_NEVER=true"

This can't be applied for an entire stage directly, but you can apply the applicable only:/except: or rules: for each job in the stage you want to control.

like image 66
sytech Avatar answered May 31 '26 12:05

sytech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!