JobDSL - Create a new job if it doesn't exist in Jenkins already

4.4k views Asked by At

I created this Groovy JobDSLs script to generate a new Jenkins jobs.

List screen = [["AAA", "Description" ],["AAA", "Description" ]]
for (item in screen) {
    job(item[0]) {
        description(item[1])
        steps {
            shell('command ...')
        }
    }​
}​

Is there a way how to tell JobDSL plugin to not create a job in the List, if it already exists in Jenkins? I don't want to keep to separate files for generating new jobs. One file for new jobs and one file for all existing jobs.

1

There are 1 answers

1
daspilker On BEST ANSWER

If a job definition does not change, Job DSL does not update a job.

If a job definition changes and you want to ignore these changes, select the Action for existing jobs and views: Ignore changes option in the Process Job DSLs build step.

If you are doing this programatically with jobDsl in groovy pipeline, it may look like this:

jobDsl targets: 'jobs/**/seed.groovy', ignoreExisting: true