问题描述
我正在尝试在Jenkins的API端点上的gitlab-ci文件中执行cURL命令以启动作业,但是无论我尝试执行什么操作,第二个参数始终会被丢弃.这是我的gitlab-ci文件:
I'm trying to do a cURL command in my gitlab-ci file on a Jenkins' API endpoint to start a job, but no matter what I try the second parameter always gets dropped. Here is my gitlab-ci file:
selenium_test:
stage: run_test
tags:
- autotest1
only:
- trigger
script:
- jenkins_response=$(curl -s -I -X POST http://user:token@localhost:8080/job/qTest/buildWithParameters?environment=CI%20Dev&test_id=96)
使用上面的代码,test_id=96
被删除.如果我像test_id=96&environment=CI%20Dev
这样反转参数的顺序,则environment=CI%20Dev
会被删除.
With the code above, the test_id=96
gets dropped. If I reverse the order of the parameters like so test_id=96&environment=CI%20Dev
then the environment=CI%20Dev
gets dropped.
我也尝试像environment%3DCI%20Dev%26test_id%3D96
这样对整个字符串进行编码,但这也不起作用.
I've also tried encoding the entire string like so environment%3DCI%20Dev%26test_id%3D96
but that didn't work either.
Jenkins的两个参数test_id和environment在Jenkins中配置为字符串.
The two Jenkins' parameters, test_id and environment, are configured in Jenkins as strings.
关于我在做什么错的任何想法吗?
Any ideas on what I'm doing wrong?
推荐答案
您没有在转义外壳特殊字符(&).考虑以下两个片段:
You are not escaping shell special character (&). Consider following two snippets:
-
curl http://urlecho.appspot.com/echo?status=200&body=ALLOK
将删除第二个参数并返回None
和
curl http://urlecho.appspot.com/echo?status=200&body=ALLOK
which will drop second argument and returnNone
and
curl "http://urlecho.appspot.com/echo?status=200&body=ALLOK"
将解释第二个参数并返回正确的ALLOK
响应.
curl "http://urlecho.appspot.com/echo?status=200&body=ALLOK"
which will interpret second argument and return proper ALLOK
response.
您有两种选择:将完整的网址括在双引号中,或转义&就像您在示例中使用空格字符一样.请考虑以下 cURL文档的建议:
You have two options: to enclose full url in double quotes or to escape & like you did with space character in your example. Consider following suggestion from cURL documentation:
这篇关于gitlab-ci文件中对Jenkins API的cURL命令正在删除参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!