0

I have set a global environment varaiable in jenkins - flag which takes in values on and off

I have multiple declarative pipelines in jenkins, some of which get triggered based on timers.

Now I don't want the timers to trigger the scheduled pipelines when flag is set to on.

One way is to use the when {expression {env.flag == 'off' }} in all the stages in all the pipelines triggered by timer. I can't even apply it to stages at once but instead have to apply it individually to all stage inside stages. Is there a better way?

How can I accomplish this, preferably without installing any new plugins?

1 Answer 1

1

One solution could be to throw an error if flag = on in the beginning of your pipeline, but that would mean having a failing pipeline as soon the flag is on. But you can avoid the FAILURE with some post function treatment.

Else you can try using scripted pipeline instead of declarative one :

node('your node'){
 if(!flag){
  stage(){...}
 }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.