简体   繁体   中英

How do I retrieve my custom variables from a Bamboo Atlassian Build Plan via REST API

I have a bamboo plan that runs on every commit to a github pull request. In that bamboo plan there are a few custom variables on it such as Git Sha, Github Pull Request Number, etc.

I want to write a script that stops all previous builds (multiple concurrent builds) that have the same pull request number -- same custom variable value.

The reason for this is that if someone makes a quick change to their pull request (comments on the review, etc) that we don't have multiple builds running when only the last one is necessary.

I know it is possible to stop a build with a rest request, but I need a way to be able to get all running builds with custom variable value = 27 (pull request number). Once I know this, I can proceed.

At the time of writing, the REST API documentation doesn't list any method of querying the running builds for a particular build variable.

A solution would be to create your own plugin for Bamboo that exposes a REST service that does this query for you, but I don't know which of the Java APIs you would need to use in order to perform that query.

Here is how I solved this ...

You can call /rest/api/latest/result/<plankey>-latest?includeAllStates=true&expand=variables where plankey is the key for the specific Bamboo build plan.

You then loop through the results you get back, looking for a lifeCycleState value that is not Finished , and a custom variable with the desired name to see if it matches the PR number you have.

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