API (curl)用于在 Jenkins 中批准升级构建作业的命令

API (curl)Command to Approve a promoted build Job in Jenkins

有没有什么方法可以让审批者使用 curl 命令批准特定的构建?

我正在使用 Promoted Builds 插件来手动批准构建。

当我在 curl 命令下尝试时,它给出了 "Error 400 Nothing is submitted"。我到处搜索但无法得到正确的答案。请帮助

卷曲http://admin:XXXXXXXXXXXX@JENKINS_URL/job/JOB_NAME/129/promotion/promotionProcess/PromoteForTesting/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve?token=abcde1234

当我试图传递 JSON 数据时,它正在抛出 "Error 403 No valid crumb was included in the request"

命令是 curl http://admin:XXXXXXXXXXXX@JENKINS_URL/job/JOB_NAME/129/promotion/promotionProcess/PromoteForTesting/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve?token=abcde1234 --data-urlencode json='{&Submit=Approve}'

我按照这个 API support for manual approval of promoted builds in Jenkins? post 作为参考,但运气不好

是的,经过多次即插即用后终于找到了解决方案。想分享一下,因为它可以帮助其他人。 首先,我传递的 Json 值不正确,它没有促销期望的所有参数。其次,因为我启用了 CSRF 保护,所以 HTTP 请求应该有一个有效的碎屑。所以我所做的是我手动批准了一些虚拟工作并获得了成功提升工作的 JSON 。它包含所有传递的参数。所以它帮助我获得了应该从 CURL 命令传递的所有参数。所以最后工作 URL 在下面。您可以根据需要 pass/remove JSON DATA 的任何其他参数。

请注意:crumb 字段名称已根据许多 Whosebug 答案中提供的答案进行了更改。现在文件名不是“.crumb”而是 "Jenkins-Crumb"

curl -v -H "Jenkins-Crumb:XXXXXXXXXXX" -X POST http://USER:TOKEN@JENKINS_URL/job/JOB_NAME/JOB_NUMBER/promotion/promotionProcess/PromoteForTesting/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve --data-urlencode json='{"parameters":[{"_class ":"hudson.model.StringParameterValue","name":"PARAMETER","value":""},{"_class":"hudson.model.StringParameterValue","name":"Job","value":"Deploy(ZettaDevelopment)"},{"_class":"hudson.model.StringParameterValue","name":"BuildSelection","value":"PARAMETER" },{"_class":"hudson.model.StringParameterValue","name":"PARAMETER","value":"PARAMETER"}]}'

传递的参数值是使用http://USER:TOKEN@JENKINS_URL/job/JOB_NAME/JOB_NUMBER/promotion/promotionProcess/PromoteForTesting/promotionBuild/Build_NUMBER/api/json

找到的

这里Build_NUMBER是我手动批准的版本。从输出中你可以很容易地得到需要传递的参数。

希望这至少对我有用:-)