Jenkins REST buildWithParameters的JSON格式是什么,以覆盖默认参数值 [英] What is the format of the JSON for a Jenkins REST buildWithParameters to override the default parameters values

查看:1000
本文介绍了Jenkins REST buildWithParameters的JSON格式是什么,以覆盖默认参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过发送POST调用,我可以使用其参数的默认值构建Jenkins作业 http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters

I am able to build a Jenkins job with its parameters' default values by sending a POST call to http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters

,我可以通过发送到以下URL来覆盖默认参数"product","suites"和"markers": http://jenkins:8080/view /Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product = ALL& suites = ALL& markers = ALL

and I can override the default parameters "product", "suites" and "markers by sending to this URL: http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=ALL&suites=ALL&markers=ALL

但是我看到了一些示例,可以通过发送带有新值的JSON正文来覆盖参数.我正在尝试通过发送以下json主体来做到这一点.他们都不适合我.

But I saw examples were the parameters can be override by sending a JSON body with new values. I am trying to do that by sending the following json bodies. Neither of them works for me.

{
        'product': 'ALL',
        'suites': 'ALL',
        'markers': 'ALL'
}

{
  "parameter": [
        {
            "name": "product",
            "value": "ALL"
        },
        {
            "name": "suites",
            "value": "ALL"
        },
        {
            "name": "markers",
            "value": "ALL"
        }
  ]
}

如果我想覆盖参数"product","suites"&的值,该发送什么JSON? 标记"?

What JSON to send if I want to override the values of parameters "product", "suites" & "markers"?

推荐答案

我将保留原始问题,并在此处详细说明触发参数化构建的各种API调用.这些是我使用的通话选项.

I'll leave the original question as is and elaborate here on the various API calls to trigger parameterized builds. These are the calls options that I used.

其他文档: https://wiki.jenkins.io/display/JENKINS /Remote + access + API

该作业包含3个参数,分别为:产品,套件,标记

The job contains 3 parameters named: product, suites, markers

  1. 将参数作为URL查询参数发送到/buildWithParameters : http://jenkins:8080/view /Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product = ALL& suites = ALL& markers = ALL

将参数作为JSON数据\有效载荷发送到/build : http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build

Send the parameters as JSON data\payload to /build: http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build

JSON数据\有效负载不作为调用的json_body发送(这让我感到困惑),但在数据有效负载中的评分器为:

The JSON data\payload is not sent as the call's json_body (which is what confused me), but rater in the data payload as:

json:'{
       "parameter": [
                     {"name":"product", "value":"123"}, 
                     {"name":"suites", "value":"high"}, 
                     {"name":"markers", "value":"Hello"}
                    ]
      }'

以下是上述每个调用的CURL命令:

And here are the CURL commands for each of the above calls:

curl -X POST -H"Jenkins-Crumb:2e11fc9 ... 0ed4883a14a" http ://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build --user"raameeil:228366f31 ... f655eb82058ad12d" -form json ='{"parameter":[{"name :" product," value:" 123},{" name:" suites," value:" high},{" name:" markers," value:" Hello} ]} '

curl -X POST -H "Jenkins-Crumb:2e11fc9...0ed4883a14a" http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build --user "raameeil:228366f31...f655eb82058ad12d" --form json='{"parameter": [{"name":"product", "value":"123"}, {"name":"suites", "value":"high"}, {"name":"markers", "value":"Hello"}]}'

卷曲-X POST \ ' http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters ?product = 234& suites = 333& markers = 555 " \ -H'授权:基本c2hsb21pb ... ODRlNjU1ZWI4MjAyOGFkMTJk'\ -H'cache-control:no-cache'\ -H'jenkins-crumb:0bed4c7 ... 9031c735a'\ -H'邮递员令牌:0fb2ef51 -...-...-...- 6430e9263c3b'

curl -X POST \ 'http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=234&suites=333&markers=555' \ -H 'authorization: Basic c2hsb21pb...ODRlNjU1ZWI4MjAyOGFkMTJk' \ -H 'cache-control: no-cache' \ -H 'jenkins-crumb: 0bed4c7...9031c735a' \ -H 'postman-token: 0fb2ef51-...-...-...-6430e9263c3b'

要发送给Python请求的内容 为了在Python中发送上述调用,您需要传递:

What to send to Python's requests In order to send the above calls in Python you will need to pass:

  1. headers = jenkins-crumb
  2. auth =您的(用户名,user_auth_token)的元组
  3. data =字典类型{'json':{"parameter":[....]}}的json字符串

这篇关于Jenkins REST buildWithParameters的JSON格式是什么,以覆盖默认参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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