Blog | CloudStakes Technology
1709707168Steps to Create Seed Job for Jenkins Pipeline.webp

Steps to Create Seed Job for Jenkins Pipeline

user-img

Nikita Gill

8th February 2022

In Jenkins, the Seed Job is just like the normal Jenkins Job that processes the Job DSL script, encompassing instructions to create other jobs. To create a seed Job, a Job DSL Plugin must be installed on your Jenkins’ server plugin list, which then helps you define the job and incorporate it with the seed job automating the creation of additional jobs. 

In this article, you will know how to install the Job DSL plugin and create a seed job on the Jenkins pipeline for the DevOps project. So, let’s get started: 

Step 1: Installing the Job DSL Plugin 

The Job DSL plugin offers many Job DSL features that can help you throughout your Jenkins Job creation process. 

1. Navigate to your_jenkins_url/pluginManager/available 

2. There you’ll find a search box, now type Job DSL. 

3. In the resulting plugin list, check for the Job DSL in list. If you don’t find the Job DSL, consider it as it is either already installed in or the plugin list in the Jenkins server is not updated. 

4. If you find the Job DSL in the list, select it and click on the Install without restart option.

Note:   

  • You can check the already installed Job DSL plugin by navigating to your_jenkins_url/pluginManager/installed 
  • Update Jenkins Server’s Plugin list through your_jenkins_url/pluginManager/available and click the Check Now button available at the bottom of the plugin list.

 

Once the Job DSL plugin installation initiates, you’ll be redirected to the page showing the installation progress. Now, you’ll need to wait for the Job DSL installation process to get the Success sign and completion of Loading plugin extensions before jumping to the next step.

Now, you’re all set to use the Job DSL plugin for configuring or creating (seed) jobs as script/code. 

Step 2: Creating a Seed Job

In this step, you will write a demo Job DSL script and add it into the seed job. In this, you’ll define a simple job printing ‘Hi There!’ message in the Job console output. 

A Job DSL script is written with API methods aligned by the Job DSL plugin, which help to define aspects of a job, like a type (freestyle or pipeline jobs), build triggers and parameters, create post-build actions, and more. 

Now, let’s create a ‘Hi There!’ job using a job API method (freeStyleJob – an alias of the job). Navigate to the job method documentation.

Click on the ellipsis icon (…) present in the first line of the code job (String name) { … } to see the available methods and blocks.

You can also expand these child blocks to see their methods and blocks. Now, click on the steps ( … ) to expand the shell (String) method for running a shell script.

Write a Job DSL script, printing ‘Hi There’ using the shell method.  

job('demo') {    steps {        shell('echo Hi There!')    }}  

You'll need a seed job to run this script.

Steps to create a seed job:

1. Navigate to your_jenkins_url.

2. Click on the New Item link available on the left side of the dashboard.

3. Type seed in the search section, select Freestyle project

4. Click on the OK button.

Now, you can see the Build section in the screen, scroll down the Add build step menu, and select Process Job DSLs.

From this section, you can configure the seed job using two methods either by selecting the Use the provided DSL script or Look on Filesystem.

Here, we’ll go for the first option.

Select the Use the provided DSL script and paste your ‘Hi There!’ Job DSL script in the text box, visible in the right side of the screen.

Click the Save button, which will create the seed job and navigate you to the seed job page.

Go to the your_jenkins_url section and confirm your created seed job.

Finally, you’ve successfully created your seed job incorporating Job DSL script, which then you can execute to let it create other jobs for various aspects automatically. 

Have Queries?

Keep reading our blogs to know more about Jenkins, its integration processes, and more about our DevOps service and solutions. Have DevOps solution-based project for us? Book your first free 60 mins of DevOps consultation with our DevOps experts.