How to link jobs in Jenkins

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

  1. project1 generates first_project.txt file
  2. project2 generates second_project.txt file
  3. project3 generates artifacts from jobs project1 and project2

Install the required plugins in Jenkins dashboard:

  1. Go to Manage Jenkins --> Manage plugins --> Available --> search by keyword
  2. Install the Parameterized Trigger plugin
  3. Install the Copy Artifact plugin
  4. Install via Download now and install after restart option

Create the first project:

  1. Create a freestyle project with the name project1
  2. Project must be parameterized. Add the person_name parameter: parameter
  3. Add the build step with a simple shell script: build
  4. Add post-build action to archive and fingerprint text file: archive
  5. Save the project and run the job once to check if everything works as intended: project

Create the second project

  1. Create a freestyle project with the name project2
  2. 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): project2
  3. Add shell script in build step: build2
  4. Add post-build action to archive and fingerprint second_project.txt file: archive2
  5. 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
  1. Go to project1 configuration and add a post-build action with Trigger parameterized build on other projects option: link
  2. From the dashboard start project1 job and wait until triggered project2 job is finished with the following message: Hi Maxat: job

Create the third project:

  1. Create a freestyle project with the name project3
  2. As all of the jobs we created under the same user, you don't need to select Permission to Copy Artifact option
  3. Go to Build and select Copy artifacts from another project: build3
  4. Add another build step with a shell script: shell3
  5. Add post-build action to archive all of the artifacts: post
  6. Save the project and check if build is successful: build
  1. Go to project2 --> post-build action and select Build other projects:
  2. Now test by going to the project1 and running it with another value:
  3. Once project2 and project3 finished their jobs, go to project 3 and check if you have the successful build: