mohamicorp / stash-jenkins-postreceive-webhook

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

Trigger seems to be not working - how to debug #21

Closed martinburger closed 11 years ago

martinburger commented 11 years ago

Hi!

I set up a post receive hook in order to trigger a Jenkins build as soon as there is a change committed to branch develop. Rationale: we do not want to wait until Jenkins would poll for changes but to proactively start a new build the moment some change was committed.

In Stash, I configured Stash Post-Receive Webhook to Jenkins with the following values:

In Jenkins, I am using the following configuration (among other settings, obviously):

However, it seems that Stash Post-Receive Webhook never connects to Jenkins. At least, no new build gets scheduled.

Why is it required to enable the "Poll SCM option" anyway? I actually want to trigger builds remotely via the Stash Post-Receive Webhook and not via Jenkin's polling mechanism. I think there is a misunderstanding on my part, right?

Regards,

Martin

mikesir87 commented 11 years ago

Hey there! Thanks for the issue post and especially for all of the info. It's nice to be given enough context around what's going on!

The problem is that the plugin currently only works in conjunction with the GitHub plugin, using the default webhook endpoint that it uses. Based on the info you provided above, when you are making commits, a GET request is being made to

https://jenkins.local/job/product-develop/build?token=foobar&cause=Triggered%20by%20Stash%20Post-Receive%20Webhook/git/notifyCommit?url=ssh://git@stash.local:7999/PROD/code.git

which obviously isn't the right URL for what you are trying to do. You can tail your Jenkins access log to verify that this is the case.

The Git plugin, when using the /git/notifyCommit endpoint requires polling to be enabled. They decided this to prevent people from triggering builds on your server when there isn't anything to build. Basically, when the endpoint is accessed, a poll is triggered and if there are updates to the repo, a build is performed.

So... what needs to be done? There's been several other people that have said it would be nice to provide the webhook URL, rather than having the plugin create it. By providing this functionality, it would solve your problem as well.

Let me think about this a little more and how it would be implemented and get back to you.

warmfusion commented 11 years ago

The Jenkins URL needs to be the root directory of your jenkins installation as the plugin uses the Jenkins build API to trigger jobs; specifically http:///jenkins/git/notifyCommit?url=

Jenkins will receive the git url and look at any jobs that need to be run for that url, triggering if necessary. You can try it out yourself by simply appending the url in your browser and seeing the response.

As such, your configuration should be:

Stash:

Jenkins: As you have above, but you could reducing polling to "@midnight" to reduce overheads.

Note that the Git url appears to be CaSe SeNsItIvE between systems

The "Polling SCM" is required, I believe, due to the way the Jenkins architecture works.

martinburger commented 11 years ago

@warmfusion: Thanks, using the root URL works perfectly.

kuhnroyal commented 11 years ago

Just a little correction, the Jenkins Github plugin is not required, the Git plugin is.

mikesir87 commented 11 years ago

That's correct. Nice catch there.

ghost commented 10 years ago

What is the syntax used when authentication is set up for jenkins? This looks anonymous is allow to login to jenkins https://jenkins.local/