Steps to Create Seed Job for Jenkins Pipeline

shape
shape
shape
shape
shape
shape
shape
shape
create jenkins seed job

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.

  • Navigate to your_jenkins_url/pluginManager/available.
  • There you’ll find a search box, now type Job DSL.
  • In the resulting plugin list, check for the Job DSL in the 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.
  • If you find the Job DSL in the list, select it and click on the Install without restart option.

Check the Job DSL in the Jenkins Plugin Manager

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.

Install Job DSL Plugin

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 to 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.

Job API 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.

Jenkins Job building steps

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:

  • Navigate to your_jenkins_url.
  • Click on the New Item link available on the left side of the dashboard.
  • Type seed in the search section, select Freestyle project
  • Click on the OK button.

creating freestyle project (seed job)

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

Job build steps

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 on the right side of the screen.

Create a seed job with/using provided DSL script

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

check seed job status

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

confirm seed job status

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.

Supportscreen tag