如何使用curl、http发送布尔参数?

问题描述 投票:0回答:2

我尝试使用curl、http-get 向Jenkins 发送布尔参数,但没有成功。需要有人告诉我这里出了什么问题。

我确实尝试将其发送为

true
True
1
但这些都不起作用。

jenkins中的Job被设置为pipeline并被参数化。 GUI 添加了 3 个参数:

  • bp1 布尔值 1
  • bp2 布尔值 2
  • sp string(这个是检查参数是否发送了

默认值如下:

  • bp1 - 假
  • bp2 - 假
  • sp - 空

管道代号:

stage ('bools') {
    echo 'bool 1 is:' + params.bp1
    echo 'bool 2 is:' + params.bp2
    echo 'string is:' + params.sp
}

用于调用构建的命令(在浏览器或邮递员中):

http://X.X.X.X/jenkins/job/bool_debug/buildWithParameters?token=booltest&bp1=true&bp2=false$sp='this is text from param'

预期结果是

bool 1 is:true
,但得到了
bool 1 is:false
。从 API 调用时,Jenkins 没有更改(勾选复选框)布尔参数。其他方式:

我得到了什么:

Running in Durability level: MAX_SURVIVABILITY
[Pipeline] stage
[Pipeline] { (bools)
[Pipeline] echo
bool 1 is:false
[Pipeline] echo
bool 2 is:false
[Pipeline] echo
string is:'this is text from param'
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS

应该是什么:

Running in Durability level: MAX_SURVIVABILITY
[Pipeline] stage
[Pipeline] { (bools)
[Pipeline] echo
bool 1 is:true    <--------------------------
[Pipeline] echo
bool 2 is:false
[Pipeline] echo
string is:'this is text from param'
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS
jenkins parameters boolean
2个回答
0
投票

面对同样的问题,认为是Jenkins的bug。我最终创建了另一个管道,它使用参数触发所需的管道作为解决方法。


0
投票

我们正在使用 Jenkins 2.387.1 并使用 HTTP POST 和

content-type: application/x-www-form-urlencoded
在正文中将布尔参数作为(字符串)
true
传递,从而使参数正确启用。

HTTP GET 是问题所在,POST 会有所帮助,或者同时已修复。

© www.soinside.com 2019 - 2024. All rights reserved.