api - TeamCity - 如何通过 REST API 取消多个构建
问题描述
你好 DevOps 布道者!
首先,感谢这个答案,我能够使用以下 curl 成功取消单个 TeamCity 构建:
curl http://teamcity:8111/app/rest/buildQueue/buildType:<buildId> \
-X POST -u *** \
-H 'Content-Type: application/json' -d '{
"buildCancelRequest": {
"comment": "This build was cancelled.",
"readdIntoQueue": "false"
}
}'
但是,我的想法是通过 TeamCity REST API 取消特定项目中的多个构建。我尝试了以下方法:
curl http://teamcity:8111/app/rest/buildQueue/project:<projectId>,count:<n> \
-X POST -u *** \
-H 'Content-Type: application/json' -d '{
"buildCancelRequest": {
"comment": "Only one build was cancelled.",
"readdIntoQueue": "false"
}
}'
不幸的是,我失败得很惨,因为这个项目中只有一个构建被取消了。我知道我可以发送这个请求的次数与项目中的构建次数一样多,但是这个丑陋的解决方法!我想把它做好!有人可以告诉我如何使用 TeamCity REST API 取消项目中的所有构建吗?
解决方案
由于时间紧迫且没有给出答案,我被迫使用解决方法,因此基于此答案,我准备了以下请求:
curl http://teamcity:8111/app/rest/buildQueue/project:<projectId>,count:[1-n] \
-X POST -u *** \
-H 'Content-Type: application/json' -d '{
"buildCancelRequest": {
"comment": "Multiple builds will be cancelled.",
"readdIntoQueue": "false"
}
}'
您只需将n替换为您在所选项目中拥有的构建数量即可将它们全部取消。它基本上发送多个请求,这意味着停止所有排队的构建。
但是,如果您想停止已经运行的构建,则需要达到不同的端点:
curl http://teamcity:8111/app/rest/builds/project:<projectId>,running:true,count:[1-n] \
-X POST -u *** \
-H 'Content-Type: application/json' -d '{
"buildCancelRequest": {
"comment": "Already running builds will be stopped.",
"readdIntoQueue": "false"
}
}'
如果您知道每个项目只会运行一个构建,那么您可以跳过count:[1-n]
定位器,并且只会发送一个请求,这将停止当前在所选项目中运行的构建。
推荐阅读
- python - 上传的文件/块正在消失
- python - 在 Python 中使用 sqlite3 内存模式作为缓存是个好主意吗?
- flutter - Flutter - 对齐和包装问题
- .net - mac/linux `dotnet build` 没有找到框架“.NETFramework..”的参考程序集
- c - 这个 C 程序可以工作,但编译会产生错误。为什么?
- java - 为什么 this.getClass().getName() 会产生与 StackTraceElement.getClassName() 不同的结果?
- java - Java - 从 Spring Boot 应用程序中获取变量
- python - 我如何根据键值将python dict排序为嵌套列表
- node.js - Sequelize (with Postgres) - 用 engine = postgres 定义一个新模型
- ubuntu - 在 ubuntu1604 上安装 SGE