I am trying to obtain the last build number (for a specific job) from jenkins from a remote script.
I have thus:
<jenkins url>/api/xml?tree=jobs[name,lastBuild[number]]
Producing
<hudson>
<job>
<name>mfg-tools-build-win32</name>
<lastBuild>
<number>220</number>
</lastBuild>
</job>
...
<job>
<name>client-sign</name>
<lastBuild>
<number>103</number>
</lastBuild>
</job>
...
I wan to get the number ("103") of the job where the name is "client-sign".
I tried to restrict the job entries returned:
<jenkins url>/api/xml?tree=jobs[name[contains(.,'luna-dev-sa7-evcs-client-sign')],lastBuild[number]]
But that changed nothing in the output.
Tried using some xpath I found on the hudson doc site:
<jenkins url>/api/xml?xpath=/hudson/job/name/text()[contains(.,%27client-sign%27)]
But that wound up giving me an error indicating two nodes matched (there is one tagged as 'client-sign-copy').
What xpath do I need to pluck the last build #?
Update:
Per request: https://wiki.eclipse.org/Hudson-ci/help/remote_access_api#XPath_Selection
Update 2:
I might not be able to do this. I got further via working with the previous answer (that is now deleted):
<jenkins url>/api/xml?depth=1&xpath=//job[name = "client-sign"]/lastBuild/number/text()
But, that now throws:
primitive XPath result sets forbidden; implement jenkins.security.SecureRequester
Unless that is also wrong, I guess I'm back to screen-scraping. >:-[
Update 3 - Success (but not with XPath)
From this answer, I was able to come up with
<jenkins url>/job/client-sign/lastBuild/buildNumber
And that gives me 103, just as needed. :)