[英]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.我有一个竹子计划,它在每次提交 github 拉取请求时运行。 In that bamboo plan there are a few custom variables on it such as Git Sha, Github Pull Request Number, etc.
在那个竹子计划中有一些自定义变量,例如 Git Sha、Github Pull Request Number 等。
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).我知道可以通过休息请求停止构建,但我需要一种方法来使用自定义变量值 = 27(拉取请求编号)获取所有正在运行的构建。 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.在撰写本文时, REST API 文档未列出任何查询特定构建变量的正在运行的构建的方法。
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.一个解决方案是为 Bamboo 创建您自己的插件,该插件公开一个为您执行此查询的 REST 服务,但我不知道您需要使用哪些 Java API 来执行该查询。
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.您可以调用
/rest/api/latest/result/<plankey>-latest?includeAllStates=true&expand=variables
其中plankey
是特定 Bamboo 构建计划的关键。
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.然后,您遍历返回的结果,查找不是
Finished
的lifeCycleState
值,以及具有所需名称的自定义变量,以查看它是否与您拥有的 PR 编号匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.