Trigger parameterized builds through api calls - jenkins

I am trying to trigger the Jenkins builds through API calls everything is working without parameters.
If i am trying with parameters job is not getting triggered.
curl -I -u tmp:apitoken http://jenkinurl:8080/job/test02/build/buildWithParameters?token=rahul&branchName=rahul

Used wrong syntax.
curl -I -u tmp:apitoken "http://jenkinurl:8080/job/test02/buildWithParameters?token=rahul&branchName=rahul"
If in the case of Multiple parameters
curl -I -u tmp:apitoken http://jenkinurl:8080/job/test02/build/buildWithParameters?token=rahul&param1=value&param2=value

Related

Trigger Jenkins build via curl with additional parameter

I'm trying to trigger the Jenkins build via curl command with additional parameter as described in the following image:
I'm using --data-urlencode json='{"parameter": [{"name":"text", "value":"develop:test"}]}' but it doesn't work.
curl -X POST --user "${userName}:${password}" -H "Jenkins-Crumb:33c13aed5548ad43bf5e2eb276cf21af" "JENKINS_URL/job/JOB_NAME/buildWithParameters" --data-urlencode json='{"parameter": [{"name":"text", "value":"develop:test"}]}'
JenKins still build with the default parameter instead:
Any solution? Thanks.

Docker Hub Remtoe Build Triggers

https://docs.docker.com/docker-hub/builds/#remote-build-triggers
Docker hub now has a build system in place. One of the ways to trigger a container to be built is using Remote build triggers. COmmands such as the following:
$ curl --data build=true -X POST https://registry.hub.docker.com/u/svendowideit/testhook/trigger/be579c82-7c0e-11e4-81c4-0242ac110020/
Their website shows a few paramters that can be passed in. But does not explain their meaning, nor do they provide a list all possible parameters.
What are all the possible parameters and what are their meanings?
it works for branches for sure, not sure about tags:
curl -H "Content-Type: application/json" \
--data '{"source_type": "Branch", "source_name": "develop"}' \
-X POST "$DOCKERHUB_TRIGGER";
Try source_type = Tag

jenkins Job Status via Curl

I need to get job build status failure or success via curl command.
I tried this :
curl --silent http://user:TokenID#Jenkins-BuildURL/job/job_number/api/json | jq -r '.result'
Unable to execute the curl.
Try below Command :
FYI , you are missing JOB_NAME in your curl command
curl --silent http://user:TokenID#Jenkins-BuildURL/job/${JOB_NAME}/${BUILD_NUMBER}/api/json
Note : JOB_NAME,BUILD_NUMBER are jenkins Environment variables , when executed from jenkins job it will pick latest job details
and you can always pass your credentials using '-u' option :
Example :
curl --silent -u username:user_pwd http://Jenkins-BuildURL/job/${JOB_NAME}/${BUILD_NUMBER}/api/json
And simple trick would be first check in browser if the Url is valid or not , if it valid half of the problem is eliminated , then we can focus on curl command

How can I retrigger the same jenkins build again

I am connected between jenkins and gerrit successfully. The gerrit trigger is on every new change. Sometimes the build is not started (no matter what is the reason).
How can I start the exact same build by passing a variable from gerrit?
I want to clone exactly the same changes as they are pushed to gerrit.
For now I can start the build with this command:
curl -u user:password jenkins_url/job/job_name/build?token
Is there a way to start this build with gerrit param?
For example
curl -u user:password jenkins_url/job/job_name/build?token param=change-id
Yes, you can trigger a build passing a parameter with the following command:
curl -u USER:PASS "https://JENKINS-SERVER/JOB-PATHNAME/buildWithParameters?token=TOKEN&PARAM-NAME-1=PARAM-VALUE-1&PARAM-NAME2=PARAM-VALUE-2"

Trigger jenkins job with parameters from shell

I am trying to trigger a trigger jenkins job from shell but as of now no sucess.I tried both these methods
curl -u ceadmin:ceadmin -X POST http://abc-lnx:8080/job/ci_demo/build --data token=ci_build -data-urlencode json='{"parameter": [{"name":"Branch", "value":"master"}, {"name":"verbosity", "value":"high"}]}'
curl -X POST http://abc-lnx:8080/job/ci_demo/buildWithParameters?token=ci_build&Branch=master
I have defined ce_admin as token in my job. also ce_admin is a admin user in Jenkins.Anonymous user do not have any permission other then read on jobs and views.
What am i missing?
This works for me:
#parameters:
username=user
password=password
jenkins_url=example.com/build
some_token=hi
job_name=dostuff
curl -u $username:$password -X POST https://$jenkins_url/job/$job_name/build\?token\=$some_token
So this should work for your example (I escaped "?", and "&"):
curl -u ceadmin:ceadmin -X POST http://abc-lnx:8080/job/ci_demo/buildWithParameters\?token=ci_build\&Branch=master

Resources