Overview:
This simple project shows how to link different jobs in Jenkins and pass parameter values with artifacts between them.
The overall scheme of the project: project1 --> project2 --> project3
- project1 generates
first_project.txt
file - project2 generates
second_project.txt
file - project3 generates artifacts from jobs project1 and project2
Install the required plugins in Jenkins dashboard:
- Go to Manage Jenkins --> Manage plugins --> Available --> search by keyword
- Install the Parameterized Trigger plugin
- Install the Copy Artifact plugin
- Install via Download now and install after restart option
Create the first project:
- Create a freestyle project with the name project1
- Project must be parameterized. Add the person_name parameter:
- Add the build step with a simple shell script:
- Add post-build action to archive and fingerprint text file:
- Save the project and run the job once to check if everything works as intended:
Create the second project
- Create a freestyle project with the name project2
- Specify the name shell variable from the first project (default value name_is_incorrect is used when the upstream job from project1 does not pass any named parameter):
- Add shell script in build step:
- Add post-build action to archive and fingerprint second_project.txt file:
- Save the project and run the job once to check if everything works as intended. You should receive a default value Hi name_is_incorrect
Link project1 and project2 jobs:
- Go to project1 configuration and add a post-build action with Trigger parameterized build on other projects option:
- From the dashboard start project1 job and wait until triggered project2 job is finished with the following message: Hi Maxat:
Create the third project:
- Create a freestyle project with the name project3
- As all of the jobs we created under the same user, you don't need to select Permission to Copy Artifact option
- Go to Build and select Copy artifacts from another project:
- Add another build step with a shell script:
- Add post-build action to archive all of the artifacts:
- Save the project and check if build is successful:
Link project2 and project3 jobs:
- Go to project2 --> post-build action and select Build other projects:
- Now test by going to the project1 and running it with another value:
- Once project2 and project3 finished their jobs, go to project 3 and check if you have the successful build: