简体   繁体   中英

Jenkins: Get branch from last successful build

I am wondering, if Jenkins API allows to retrieve the branch of a git repository, that has been built with the last successful build of a job.

My job has a multi-branch specifier like 'developer-*', so it builds different feature branches.

Now I would like to know, which branch actually has been build by this job lately.

I can use this syntax to retrieve the last successful build with its timestamp.

http://localhost:8080/jenkins/view/myview/api/json?depth=2&tree=jobs%5BdisplayName,lastBuild%5Bbuilding,result%5D,lastSuccessfulBuild%5Btimestamp%5D%5D

However, I could not find any property name in the API documentation that would give me the branch.

Is that actually possible?

I realized that I can call

http://localhost:8080/jenkins/job/$jobname/lastSuccessfulBuild/api/json

or more precisely for my case

http://localhost:8080/jenkins/job/$jobName/lastSuccessfulBuild/api/json?tree=actions[lastBuiltRevision[branch[*]]]

as posted here .

From the response I should be able to use actions > x > lastBuiltRevision > branch > 0 > name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM