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

对着背影说爱祢 提交于 2021-01-27 19:00:06

问题


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:


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



来源:https://stackoverflow.com/questions/41285489/jobdsl-create-a-new-job-if-it-doesnt-exist-in-jenkins-already

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!