mohamicorp / stash-jenkins-postreceive-webhook

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

Trigger Build Button returns 405 #116

Closed freshp closed 5 years ago

freshp commented 9 years ago

I use Stash and Jenkins. Now I try to get the "Stash Webhook to Jenkins" to work. The configuration check of the repository results "Success!".

With the following Url I get the right jobs from jenkins http://jenkins.com/git/notifyCommit?url=ssh%3A%2F%2FmyRepository.git.

The whole configuration looks right. But I get a "405 - Method Not Allowed" from the URL: http://stash.com/rest/jenkins/latest/projects/projectName/repos/repoName/triggerJenkins?branch=branchName&sha1=sha1 This URL will be called by Trigger Build Button.

What can i do, to trigger the jobs from stash?

janmaennig commented 9 years ago

+1

mikesir87 commented 9 years ago

Hmm... I'll take a look at this. I'm assuming that the 405 you're seeing is from your Stash instance, not the Jenkins instance, correct?

Another question... are you logged in as a Stash admin when seeing this, or a normal user?

freshp commented 9 years ago

The 405 I still get, is from the Stash instance. I edited my issue.

I tested it as admin and as normal user.

ashnazg commented 9 years ago

I'm also seeing this behavior now, from the Trigger Build button on a PR, though not from the Trigger Jenkins button in the hook config. I've verified the same behavior on the Trigger Build button from a PR (405 from Apache), as well as the manual notifyCommit URL just passing the repo URL (good result of "scheduled polling" in Jenkins log).

ashnazg commented 9 years ago

Is the 405 due to that Trigger Build button doing a POST, but hitting just the URL as if it was a GET isn't allowed?

freshp commented 9 years ago

I still try to call the same URL with parameter sha1 and branch as POST, but there is still an error. Its a 415 instead of 405, but an error.

ashnazg commented 9 years ago

I eventually figured out that the URL being constructed by the PR's Trigger Build button uses the attribute "branch" rather than "branches", and the latter does work properly. I've sent a patch in (https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/pull/122).

freshp commented 9 years ago

sounds good! I tried it too, but with the same result, like before.

ashnazg commented 9 years ago

I tested out all the combinations of url&branches&sha1 query params, using a POST via Curl, and they all succeed in triggering job polling.

Now, when testing just the raw URL itself in a browser (presumably a GET), the only thing that works is using url alone. None of the other combinations result in triggered polling. Some result in a good response of "No Git Jobs", some result in Jenkins stack trace errors (these indicate that url alone is absolutely required to always be included), and one combination that will trigger builds unrelated to the sha1 value and thus result in errors during the build (because the commit can't be found in the build's tracked branch).

So, the only working way to use the URL in a browser is the pass only the url. Using Curl to send a POST, however, shows me that every possible combination of the three args is acceptable and works correctly to trigger SCM polling.

ashnazg commented 9 years ago

Hitting the Stash-targeted URL directly in a browser gives me 405s no matter what combination of args I give it. I take this to mean the URL insists on a POST rather than a GET.

All those POSTs I was doing with Curl were hitting my Stash server, not Jenkins.

The only browser URL (GET?) I could get to succeed was hitting Jenkins directly with the "/git/notifyCommit?url=myrepo.git" ending.