Hi, I would like to start a jenkins job with json.
I have successfully started a Jenkins job using URL-encoded parameters. Here’s how I did it:
-H "$CRUMB" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "Component=$COMPONENT" \
--data-urlencode "APPLICATION=$APPLICATION" \
--data-urlencode "TARGET=$TARGET" \
"$JENKINS_URL/job/$JOB_NAME/buildWithParameters")
This works well for me. I can also use Bash and Python to get the build number and other details.
However, I haven’t been able to post with JSON successfully. Every time I try, Jenkins uses the default parameters instead of the ones in my JSON file. Here’s one of my attempts:
-H "$CRUMB_FIELD: $CRUMB" \
-H "Content-Type: application/json" \
--data @parameters.json \
"$JENKINS_URL/job/$JOB_NAME/buildWithParameters"
{
"parameter": [
{
"name": "value1",
"value": "choice1"
},
{
"name": "value2",
"value": "choice2"
},
{
"name": "TARGET",
"value": "your_target_value"
},
{
"name": "value4",
"value": boolean
}
]
}
And i also tried this.
-H "$(curl -u "$USERNAME:$APITOKEN" -s "http://192.168.146.133:8080/crumbIssuer/api/json" | jq -r '.crumbRequestField + ": " + .crumb')" \
-H "Content-Type: application/json" \
-d '{
"value1": "choice1",
"value2": "choice2",
"TARGET": "string",
"value4": boolean
}' \
"http://192.168.146.133:8080/job/deneme/buildWithParameters"
Still can’t do any progress about this situation and there are my questions
- How can I build with parameters using JSON?
- Do I need to use Bash or Python to get build information?
- Any suggestions or corrections?