Bear. Teddy Bear.
Bear. Teddy Bear.

Reputation: 149

HowTo Start a Jenkins build by Subversion post-commit hook? (localhost, in Windows)

I have Jenkins and Subversion installed on my Windows 7 localhost. They work fine independently.

I have the Subversion Plugin for Jenkins installed. From this page https://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin#SubversionPlugin-Windowsspecificpostcommithook I have post-commit.bat and the vbs script described.

This visual basic code fails:

url = jenkins + "crumbIssuer/api/xml?          
xpath=concat(//crumbRequestField,"":"",//crumb)"
Set http = CreateObject("Microsoft.XMLHTTP")
http.open "GET", url, False

With this error:

javax.servlet.ServletException: Must be POST, Can't be GET at hudson.model.AbstractModelObject.requirePOST(AbstractModelObject.java:88)

I think this code is getting the crumb for a CSRF protection token, but failing.

https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API says:

Jenkins uses the "Prevent Cross Site Request Forgery exploits" 
security option (which it should), when you make a POST request, 
you have to send a CSRF protection token as an HTTP request header.

I didn't turn CSRF protection on, though I know I should, out of simplicity's sake.

* I removed the GET section of the .vbs script file, so that now it just calls the POST section, and doesn't reference the crumb variable or change the request header at all, yet I still get the "Must be POST, Can't be GET" error.

What gives?

Upvotes: 0

Views: 3523

Answers (1)

Bear. Teddy Bear.
Bear. Teddy Bear.

Reputation: 149

I configured jenkins: Manage Jenkins > Configure Global Security > Check "Prevent Cross Site Request Forgery exploits" (you can leave "enable security" unchecked) > Default Crumb Issuer

And that helped a little (the GET succeeded but the POST still failed in the same way).

How to get the POST working? My question was answered by this fellow's answer. YOU MUST CONFIGURE YOUR PROJECT TO DO SCM POLLING, but don't worry, you can just set it to poll once a year.

Post-Commit Hook to trigger automatic Jenkins Build

Upvotes: 0

Related Questions