简体   繁体   English

如何使用 POST 请求中的参数使用 REST API 触发 Jenkins 管道的构建?

[英]How to trigger the build of a Jenkins pipeline using REST API with parameters in a POST request?

I made necessary setup to allow a Jenkins pipeline job to be triggered remotely using its REST API.我进行了必要的设置,以允许使用 REST API 远程触发 Jenkins 管道作业。 I'm now testing build trigger using curl.我现在正在使用 curl 测试构建触发器。

Builds are triggered properly but none of the build parameters are detected.构建被正确触发,但没有检测到任何构建参数。

  • Jenkins version is 2.210 Jenkins 版本为 2.210
  • Apache HTTPd is used as a reverse-proxy Apache HTTPd 用作反向代理
  • OS is Centos 7.x操作系统是 Centos 7.x
  • User is configured (Active Directory user)用户已配置(Active Directory 用户)
  • User has relevant permissions (Global "Read", + Job "Read","Workspace" and "Build")用户具有相关权限(全局“读取”、+ 作业“读取”、“工作区”和“构建”)
  • User has an API_TOKEN generated用户生成了一个 API_TOKEN
  • Pipeline job has an authentication token defined管道作业定义了身份验证令牌

Build history shows that no parameter passed in POST are detected.构建历史显示未检测到 POST 中传递的参数。 Only those with a default value have it displayed instead of value passed in POST request.只有那些具有默认值的才会显示它,而不是在 POST 请求中传递的值。

curl -k -X POST https://<Jenkins URL>/job/<my job name>/buildWithParameters?token=XXXXXXXXXXXXXX --user <user>:<API TOKEN> --data-urlencode json='{"parameter": [{"PARAM1": "true"},{"PARAM2": "foo"},{"PARAM3": "X.X.X.X"}]}'

I'm confused because this seemed to be the proper way to trigger a build using Jenkins API.我很困惑,因为这似乎是使用 Jenkins API 触发构建的正确方法。 How to properly trigger a pipeline job using the REST API and POST requests?如何使用 REST API 和 POST 请求正确触发管道作业?

I found a similar question:我发现了一个类似的问题:

passing parameter to jenkins job through curl POST not working? 通过 curl POST 将参数传递给 jenkins 作业不起作用?

can you try the curl -F ?你能试试curl -F吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM