How to set different environment variables in a Jenkinsfile depending on the Git branch
I want to use different variables based on the Git branch to avoid using separate Jenkinsfiles for different branches. However, it seems that Groovy syntax doesn’t work within the environment{} directive.
I tried something like this without success:
if (current_branch == 'development') { CONFIG = 100 } else if (current_branch == 'main') { CONFIG = 200 }
How do you avoid creating multiple Jenkinsfiles?
Answers
Daniel Karlsson
6 months ago
2 comments
Rating
I usually add a preliminary stage to set environment variables based on the branch:
Daniel Meier
6 months ago
Rating
Thank you very much!
Emma Johnson
2 months ago
Rating
thx all