Home > database >  Build a Jenkins job that triggers all of our other jobs with the parameters of the successful builds
Build a Jenkins job that triggers all of our other jobs with the parameters of the successful builds

Time:09-13

I have a small change that I need to push, that affect all of our 60 jobs (Jenkinsfiles). I want to test first each job (at integration) with that change. In order to do that efficiently I was thinking to build a new job that triggers all those 60 jobs, when each job parameters taken from it's last production run which finished successfully. I've start building it - at the moment the obstacle is of pulling the parameters from the latest successful runs. If one's have a better idea for testing this, I'd like to it hear as well.

More data that can help you help me: -We are using multibranch pipeline for integration -We are using groovy

Thanks!

CodePudding user response:

You could use the Jenkins API to get environment values of previous builds and then fetch the desired parameter(s):

//Get the job
projectJob = Jenkins.instance.getItemByFullName('PathOf/DesiredJobToGetParamsOf/master/')

//Get last successful build
env = projectJob.getLastSuccessfulBuild().getEnvVars()

// In env you get a list like: 
// [BRANCH_IS_PRIMARY:true, 
// BRANCH_NAME:master, 
// BUILD_DISPLAY_NAME:#29, 
// BUILD_ID:29,<many more>..., 
// param1:value1]

//Use the value of the desired parameter (e.g. "param1")
println(env["param1"])

//Output: "value1"
  • Related