Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start jenkins job immediately after creation by seed job

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.

like image 499
Jan Gassen Avatar asked Aug 28 '15 10:08

Jan Gassen


People also ask

How do you auto trigger the job in Jenkins?

Follow the steps as mentioned below to trigger a Jenkins job automatically based on GitHub's webhook configurations: Step 1: Go to the Configuration page of the respective job and under the build trigger section, check the "GitHub hook trigger for GITScm polling" checkbox and click on the Save button.


1 Answers

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')
}
like image 121
daspilker Avatar answered Oct 02 '22 12:10

daspilker