Start jenkins job immediately after creation by seed job

心不动则不痛 提交于 2020-01-02 00:58:07

问题


I'm using the Jenkins DSL plugin to automatically create build jobs for all branches of a git project. The DSL plugin is triggered by web hooks so that it is run immediately after a new branch was created. The generated build jobs for each branch are also configured to be triggered by web hooks.

The problem with the current setup is, that the build will only be executed after the second commit. The first commit will trigger the Jenkins DSL plugin to create the respective Jenkins Job and the second commit will then trigger the newly created job.

Is there any way, to start a Jenkins job immediately after it has been created by the DSL plugin? The only thing I can currently come up with is to add an additional build scheduling but I'd rather like to use web hooks only to prevent unnecessary polling.


回答1:


You can use queue DSL command to schedule a build, see https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-DSL-Commands#queue.

To queue the job only if it's new, you need to use the Jenkins API to test if the job already exists.

if (!jenkins.model.Jenkins.instance.getItemByFullName('my-job')) {
    queue('my-job')
}


来源:https://stackoverflow.com/questions/32268485/start-jenkins-job-immediately-after-creation-by-seed-job

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