sghill / grunt-jenkins

Manage Jenkins with Grunt.

Home Page:documentup.com/sghill/grunt-jenkins

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue when Jenkins installed in a non-root URL

emilioestebanez opened this issue · comments

Good afternoon,

I'm trying to use your plugin to get a backup of the Jenkins jobs in my installation. However, I'm facing an issue because my Jenkins is installed in http://localhost:8080/jenkins/ (and not on http://localhost:8080).

What happens is that it retrieves all the jobs correctly, but when trying to retrieve each job individually it constructs the URLs like this:
http://localhost:8080/jenkins//jenkins/job/Test-A-Config/config.xml

instead of
http://localhost:8080/jenkins/job/Test-A-Config/config.xml

I've seen how to fix it:
In jenkinsServer.js, line 50 I've replaced this

var path = j.url.replace(/^https?\:\/{2}[^\/]+\/(.*)/, '$1');
var url = [serverUrl, path].join('/');

with:

var path = j.url.replace(/^https?\:\/{2}[^\/]+\/(.*)/, '$1');
var serverHost = serverUrl.replace(/^(https?\:\/{2}[^\/]+)\/(.*)/, '$1');
var url = [serverHost, path].join('/');

Would it be possible for you to add this fix (or a similar one of your liking) to your published code? Because I have it running locally with the fix I mentioned above, but I'm planning to use it from the Jenkins server itself in which I don't have access to modify the jenkinsServer.js.

Thank you!

Best regards,
Emilio

Thanks for the report! As of 494dfc6, released as v0.8.0, this should just work with a context root. Would you mind giving it a try and reporting back?

For context, the regex replacement was introduced in #9. I think this is a relatively rare use-case, so it's now opt-in and by default we'll simply use the job urls returned by the Jenkins API.

Works perfectly. Thank you very much!

That's great, thanks for the followup!