1
votes

I am trying to retrieve specific jenkins details about last successful build, such as revision SHA1. I use:

https://jenkins-host/job/job-name/lastSuccessfulBuild/api/json?tree=actions[build[revision[SHA1]]]

However, this gives additional data associated with the actions field, is it possible to narrow it down to just the revision SHA1.

I know I can get buildNumber using https://jenkis-host/job/job-name/lastSuccessfulBuild/buildNumber.

Please advise.

1

1 Answers

0
votes

If you have jq(https://stedolan.github.io/jq/manual/) installed, you can use below script to get the SHA1.

$ curl $JENKINS_URL/job/<job-name>/lastStableBuild/api/json --user <user>:<token> | jq -r -j ".actions[] | select(.lastBuiltRevision) | .lastBuiltRevision.SHA1"

Replace <job-name> with the job you would like to get the revision SHA1.

Replace <user>, <token> with your own credential.