Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query for last successful build number in Jenkins with change

Example:

32 - fail
31 - stable no change (triggered by parent)
30 - stable with changes
29 - fail 
...

I want a query to return 30


So far what I got:

To query the last stable build number:

http://jenkins/job/project_name/lastStableBuild/buildNumber

This returns 31. Not exactly what I need.

To check if this build has changes, the only way I know is :

http://jenkins/job/project_name/31/api/json

Then I need to go inside the huge JSON and check if any item in changeSet > items.


Is there a easier way to query for the latest stable build with changes (30) ?

like image 491
hello_harry Avatar asked Oct 23 '15 20:10

hello_harry


People also ask

How do I get previous build number in Jenkins?

You can see all global variables at http://jenkins-url/pipeline-syntax/globals. The number can be retrieved from it. You can see all of the whitelisted calls on RunWrapper . So, in your pipeline you could do currentBuild.

How do I find the latest build in Jenkins?

I know I can call localhost/job/RSpec/lastBuild/api/json to get the status of the lastest Jenkins build.

How do you know if a Jenkins Building is successful?

Jenkins CLI's "build" command changes the exit code depending on the result of the build, as long as you use the -s or -f option at the end. Notice that the option goes at the end; it's not the first -s , which is used to define the URL of the Jenkins instance. echo $? If the result is 0, it was a success.


1 Answers

Jenkins' Remote access API with:

http://jenkins/job/<your job>/<build no>/api/xml

supports XPath, too:

XPath selection

The XML API supports a selection by XPath by using the query parameter 'xpath'. This is convenient for extracting information in environments where XML manipulation is tedious (such as shell script.) See issue #626 for an example of how to use this.
See .../api/ on your Jenkins server for more up-to-date details.

like image 138
Gerold Broser Avatar answered Oct 19 '22 20:10

Gerold Broser