我尝试使用cURL通过其API启动Jenkins构建:
#!/usr/bin/env bash
curl \
-i \
--fail \
--show-error \
-s \
-X POST \
-H 'Content-Type:application/json' \
-H 'Accept:application/json' \
--form json='{"parameter": [{"name":"COMPOSE_FULL_NAME", "value": "/redacted/docker-compose-prod.yml"}, {"name":"BRANCH", "value": "prod"}, {"name":"AD_USER", "value": "redacted"}, {"name":"AD_PASSWORD", "value": "redacted"}}]}' \
-u redactedUser:redactedToken \
-k \
https://jenkins-dck.redacted/job/elr-156344/job/stack_deploy/build \
这就是我得到的:
curl: (22) The requested URL returned error: 400 Nothing is submitted
我尝试了几种传递POST数据的方式,例如使用-d
或--data-urlencode 'json={
,但到目前为止没有成功。
知道发生了什么吗?消息说的不多,我无法访问jenkins后端的日志。
答案 0 :(得分:1)
好的,找到它了,您首先需要忽略这里的文档:https://wiki.jenkins.io/display/JENKINS/Remote+access+API。正确的方法在https://wiki.jenkins.io/display/JENKINS/Parameterized+Build
中进行了说明使用此API端点:
https://jenkins-dck.docker-prod.fr.world.socgen/job/elr-156344/job/stack_deploy/ buildWithParameters ?param1 = urlencode&param2 = urlencoded
别忘了在CURL引号中引用url,因为bash会与&符号混淆。
工作示例:
#!/usr/bin/env bash
curl \
-i \
--fail \
--show-error \
-s \
-X POST \
-H 'Content-Type:application/json' \
-H 'Accept:application/json' \
-u redactedUser:redactedToken \
-k \
"https://jenkins-dck.redacted/job/elr-156344/job/stack_deploy/buildWithParameters?BRANCH=prod&AD_USER=$SERVICE_ACCOUNT"