What are seed jobs in Jenkins and how does it work? What are seed jobs in Jenkins and how does it work? jenkins jenkins

What are seed jobs in Jenkins and how does it work?


That depends on context. Jenkins itself does not provide "seed jobs".

There's plugins that allow creating jobs from other jobs, like the excellent Job-DSL plugin. With that, you can create jobs where a groovy script creates a larger number of jobs for you.

The Job-DSL plugin refers to those jobs as "seed jobs" (but they're regular freestyle jobs). The Job-DSL plugin does not require a github connection.


The seed job is a normal Jenkins job that runs the Job DSL script; in turn, the script contains instructions that create additional jobs. In short, the seed job is a job that creates more jobs. In this step, you will construct a Job DSL script and incorporate it into a seed job. The Job DSL script that you’ll define will create a single freestyle job that prints a 'Hello World!' message in the job’s console output.

A Job DSL script consists of API methods provided by the Job DSL plugin; you can use these API methods to configure different aspects of a job, such as its type (freestyle versus pipeline jobs), build triggers, build parameters, post-build actions, and so on. You can find all supported methods on the API reference site.

The jobs we used for creating new jobs are called Seed Jobs and this seed job generates new jobs using Jenkins files (using JobDSL plugin).

Here, we disabling this feature (Enable script security for Job DSL scripts)

Jenkins Dashboard→ Manage Jenkins → Configure Global Security

Way to create seed job :

Way to create seed job

JobDSL scripts for generating new jobs.

Job1.groovy

job("Job1"){    description("First job")    authenticationToken('secret')    label('dynamic')    scm {        github('Asad/jenkins_jobDSL1', 'master')    }    triggers {        gitHubPushTrigger()       }    steps {        shell ('''    echo "test"''')    }}buildPipelineView('project-A') {    title('Project A CI Pipeline')    displayedBuilds(5)    selectedJob('Job1')    showPipelineParameters()    refreshFrequency(60)}

and create same way others Job2.groovy and so on.

For Jenkins Job DSL documentation:-Follow https://jenkinsci.github.io/job-dsl-plugin/


Think about a job - what is it actually ?

It is actually just a java/jre object that represents like this

How you generates such job/build ?

Configure Jenkins UI -> rest api to Jenkins url -> Jenkins service receive your call on the relevant endpoint -> calling to the relevant code/method and generate this new job

How Seed job will make it ?

Configure seed job on Jenkins UI only once -> run this seed job - > this code run against the internal Jenkins methods and skip all the manual process describes above

Now, when your code can talk directly to Jenkins code , things are much easier.just update your code on the relevant repo - and you are done