0

I have a pipeline job which run with below pipeline groovy script,

pipeline { parameters{ string(name: 'Unique_Number', defaultValue: '', description: 'Enter Unique Number') } stages { stage('Build') { agent { node { label 'Build' } } steps { script { sh build.sh } } stage('Deploy') { agent { node { label 'Deploy' } } steps { script { sh deploy.sh } } stage('Test') { agent { node { label 'Test' } } steps { script { sh test.sh } } } } 

I just trigger this job multiple times with different unique ID number as input parameter. So as a result i will have multiple run/build for this job at different stages.

With this, i need to trigger a multiple run/build to be promote to next stage (i.e., from build to deploy or from deploy to test) in this pipeline job as a one single build instead of triggering each and every single run/build to next stage. Is there any possibility?

2 Answers 2

2

I was also trying to do the same thing and found no relevant answers. May this help to someone.

This will read a file that contains the Jenkins Job name and run them iteratively from one single job.

Please change below code accordingly in your Jenkins.

pipeline { agent any stages { stage('Hello') { steps { script{ git branch: 'Your Branch name', credentialsId: 'Your crendiatails', url: ' Your BitBucket Repo URL ' ##To read file from workspace which will contain the Jenkins Job Name ### def filePath = readFile "${WORKSPACE}/ Your File Location" ##To read file line by line ### def lines = filePath.readLines() ##To iterate and run Jenkins Jobs one by one #### for (line in lines) { build(job: "$line/branchName", parameters: [string(name: 'vertical', value: "${params.vertical}"), string(name: 'environment', value: "${params.environment}"), string(name: 'branch', value: "${params.aerdevops_branch}"), string(name: 'project', value: "${params.host_project}") ] ) } } } } } }

Sign up to request clarification or add additional context in comments.

Comments

0

You can start multiple jobs from one pipeline if you run something as:

build job:"One", wait: false build job:"Two", wait: false 

Your main job starts children pipelines and children pipelines will run in parallel.

You can read PipeLine Build Step documentation for more information.

Also, you can read about the parallel run in declarative pipeline

Here you can find a lot of examples for parallel running

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.