Open wangming1993 opened 6 years ago
#!/bin/bash USER='' API_TOKEN='' Jenkins_IP='http://127.0.0.1:8080' CRUMB=$(curl -s "http://${USER}:${API_TOKEN}@${Jenkins_IP}//crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)") trigger_build () { jobName=$1 service=$2 data="{\"parameter\": [ {\"name\":\"SERVICE\", \"value\":\"${service}\"} ]}" curl -X POST "http://${Jenkins_IP}/job/${jobName}/job/${BRANCH}/build" \ --user "${USER}:${API_TOKEN}" \ -H ${CRUMB} \ --data-urlencode json="${data}" }
这里需要注意的是:
如果 build 的路径是 http://${Jenkins_IP}/job/${jobName}/build
build
http://${Jenkins_IP}/job/${jobName}/build
那么
data="{\"parameter\": [ {\"name\":\"SERVICE\", \"value\":\"${service}\"}, {\"name\":\"BRANCH\", \"value\":\"${branch}\"} ]}"
如果
build
的路径是http://${Jenkins_IP}/job/${jobName}/build
那么