Can we execute one pipeline from Jenkins and trigger another pipeline with inputdata from previous pipeline? If Yes, will you please provide me how?
Advertisement
Answer
Yes, you can do that. Let’s say there are two pipeline i.e. jobA and jobB. Let us assume jobA is the upstream pipeline for jobB i.e. jobB will be called or build by jobA with parameters (or input parameters from jobA).
Follow the steps below:
1) create both upstream pipeline jobA and downstream piepeline jobB (which will be called by jobA)
2) In jobB, Check the box “This project is parameterized” in configure page.
3) Click on Add Parameter drop-down and select String Parameter.
4) Fill in the name, default value and description.
5) Click on Apply and Save.
6) Go to the pipeline jobA. Create a stage similar to the stage given below in your Jenkinsfile or Pipeline as a code section.
pipeline { agent any stages { stage ('Build JobB') { steps { build job: 'jobB', parameters: [string(name: ‘Environment', value: "production")] } } } }
In this way, you can trigger Jenkins pipeline one after another.
Note: I have use declarative pipeline as code for the example. If you have, scripted pipeline or freestyle project, follow the steps upto step 5 and change the step 6 according to your pipeline.