API(curl)在Jenkins中批准提升的构建作业的命令 [英] API (curl)Command to Approve a promoted build Job in Jenkins

查看:2155
本文介绍了API(curl)在Jenkins中批准提升的构建作业的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

审批人有没有办法批准使用curl命令的特定构建?

Is there any way can an Approver approve a specific build using curl command?

我使用Promoted Builds Plugin手动批准构建。

I am using Promoted Builds Plugin for manual approval for builds.

当我试图下面的curl命令它给出错误400没有提交。我搜索无处不在,但得不到正确的答案。请帮助

when i am trying below curl command it is giving "Error 400 Nothing is submitted". I searched everywhere but couldn't get proper answer. Please help

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

当我试图传递JSON数据时,它抛出错误403请求中没有有效的碎片

When i tried to pass JSON data, It is throwing "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}'

the command is 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支持手动批准已升级建立在Jenkins?作为参考但没有运气

推荐答案

..想分享,因为它可以帮助别人。
首先,我传递的Json值不正确,它没有所有的参数。第二,因为我已经启用CSRF保护HTTP请求应该有一个有效的碎屑。所以我做的是我手动批准一些假工作,并获得成功的提升工作的JSON。它包含所有传递的参数。所以它帮助我得到应该从CURL命令传递的所有参数。所以最后的工作网址如下。您可以根据您的要求传递/删除任何其他参数到JSON数据。

Yeah finally got a solution after much plug n play.. thought to share as it could help others. First of all the Json Values i am passing are not correct and it doesn't have all the parameters the promotion expecting. Second as i have enabled CSRF protection the HTTP request should have a valid crumb. So What i did was i manually approved some dummy job and got the JSON of the successful promoted job. It contain all the passed parameters. So it helped me to get all the parameters that should be passed from CURL command. So finally the working URL is below. You can pass/remove any additional parameters to the JSON DATA as per your requirement.

请注意:碎片字段名称从许多stackoverflow答案。现在文件名不是.crumb,而是Jenkins-Crumb

Please Note: the crumb field name is changed from what much answers provided in many stackoverflow answers. Now the Filed name is not ".crumb" but "Jenkins-Crumb"

curl -v -HJenkins-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:Job,value:hudson.model.StringParameterValue,name:PARAMETER,value: Deploy(ZettaDevelopment)},{_ class:hudson.model.StringParameterValue,name:BuildSelection,value:PARAMETER},{_ class:hudson.model.StringParameterValue ,name:PARAMETER,value:PARAMETER}]}'

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是我手动批准的。

Here Build_NUMBER is the build i manually approved. From the output you can easily get the required parameters to be passed.

希望这可以帮助我至少为我工作: - )

Hope This can help as at least it worked for me :-)

这篇关于API(curl)在Jenkins中批准提升的构建作业的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆