I wanted to be able to add stage based variables for my Jenkins pipeline. Therefore I added a function which checks for a yaml named buildVars.yaml to exist, and if so, loop through the vars per stage and set them in the env. The buildVars.yaml looks something like:
unstable:
id: a
edge:
id: b
stable:
id: c
However, my pipeline now looks like this:
stages {
stage ('Prepare') {
steps {
script {
buildUtils.loadEnvVarsFromYaml()
}
}
}
stage('Starting docker build') {
...
I have to call buildUtils.loadEnvVarsFromYaml() everytime as the first step of any pipeline I have.
I would like that this function is called everytime, any pipeline starts. I don’t want to set an explicit Prepare stage in every pipeline I have, since it will be the same code over 100 times.
I have tried looking for plugins to accomplish this but I haven’t found any. I need something like a pre build step, which is executed everytime before the stages of my pipeline execute. Does anyone have any suggestions or ideas for this?
I looked for plugins that have a pre build step and I could not find any.