There are many occasions when we require our jenkins jobs to be executed in a predefined order. Jenkins Coordinator Plugin can help us achieve that.
This post will walk you through how to use this plugin to run your jobs in a particular sequence.
Suppose we have four jobs : Job1, Job2 ,Job3, Job4. We would like to execute Job1 and Job2 sequentially and Job3 and Job4 in parallel. We can also use this plugin to run our parametrized jobs, which will get clear as we will move further.
Lets begin by making Job1.
Step 1: Create a new freestyle job as shown below:
Step 2: Choose “This build is parameterized” and then the type of parameter which you want from the options in the drop down menu. We have chosen “String parameter” option for simplicity.
Step 3: We will be using this parameter value in our job which will be entered by the user. Use “Execute shell” option from the “Build” drop down menu and write an echo command to print it’s value. “Save” this job once done.
Similarly we have made our Job2 with parameter “age” , and non-parametrized Job3 and Job4.
You can download Coordinator Plugin through “Manage Plugins” option in “Manage Jenkins” tab.
After installing it, make a new coordinator project/job as shown below:
Now under the Coordinator job, make all the parameters as defined in your respective jobs.
Step1: Under the “Build” section, right-click on “Root” and click on “Create” option from the drop down menu.
Step2: Now to execute Job1 and Job2 sequentially, we have created “sequential” job under which we will be adding them.
Step3: Choose “create” option after right-clicking on “sequential” and then write the desired job names.
Step4: Here, we will be defining Job1 and Job2 as shown below :
Step5: Now, to run Job3 and Job4 parallely, again right-click on “Root” and create “parallel” job and then add both the jobs under it following the same procedure as mentioned above.
As you can see, the “S” sign on “sequential” signifies the jobs under it will run sequentially, thats by default. To run Job3 and Job4 parallely, right-click on “parallel” and choose “Swtich P” option for the same.
Step6: After completing, save changes to your job and then click on “Build with parameters” option to execute it.
Step7: Under the “Execution Plan” tab, you can still select which jobs you want to execute and under “Parameters” tab, you can define the value of the parameters which your respective jobs require.
As you can see, in the Console Output, Job2 is triggered after the success of Job1, as they were defined to be executed sequentially. And Job3 and Job4 are executed at the same time, because we defined them to be executed in parallel.