mohamicorp / stash-jenkins-postreceive-webhook

Webhook used to notify Jenkins when commits are made to Stash
Other
138 stars 100 forks source link

webhook to jenkins, trigger specific jenkins jobs? #157

Closed geirwr closed 8 years ago

geirwr commented 8 years ago

We use postreceive-webhook to ensure the build-pipeline is triggered when there are changes to repository. by default all jenkins jobs connected to this repository will trigger from a notification. But we really just want the first job of pipeline to trigger. The remaining jobs should just follow from first job, as we want the jobs to run in sequence.

We are able to get the wanted behaviour by combining bitbucket webhooks with a Jenkins Git Plugin to ignore when the notifyCommit-URL is accessed regardless of if the repository matches or not. so all but the first job in pipeline will have this "Don't trigger a build on commit notifications".

But it would be more intuitive to be able to specify a list of jobs that should run from a postreceive-notification. As it is possible to ignore commits from certain users, would it be possible to list the url of jobs that should trigger in postreceive-webhook. along this lines: http://agiletesting.blogspot.no/2015/03/triggering-jenkins-jobs-remotely-via.html

This way we specify what jobs to execute in postreceive-webhook, and avoid triggering a lot of builds erroneously,because we forget to ignore the ignore mechanism. Understand that the publish notification to jenkins about a repos-change is useful, but finer granularity would be useful

davidkarlsen commented 8 years ago

This is actually handled on the jenkins-side and configuration of triggers on the jobs, as specified in https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin "Push notification from repository". If you don't want them triggered you can set them to not poll for SCM changes. The plugin simply informs jenkins on the change, which branch and sha etc, it's jenkins that actually starts the jobs.

geirwr commented 8 years ago

Yes, I understand that it is jenkins starting the job, based on a general notification that some change happened in repository. But I have overseen the condition that Poll SCM must be enabled: "This will scan all the jobs that: Have Build Triggers > Poll SCM enabled. No polling Schedule is required."

Then there is no really no need to have more specific entries in the file hooks/post-receive to contain entries of type: curl http://jenkinsserver/job/jobname/build?delay=0sec

Then I guess the general notfication: curl http://jenkinsserver/jenkins/git/notifyCommit?url=

combined with disabling the "Poll SCM enabled" will do it