How so start a Jenkins job from another jenkins - jenkins

I am working with Ant and using jenkins to make builds.
SO, I am using jenkins and build.xml for a job. But I want to call another job in my build.xml to call another job in a different jenkins.
How can I do that?
Thanks.

Using curl you can trigger a remote jenkins job :
curl -X POST http://${user}:${password}#${jenkins_url}/job/${job_name}/build
Have a look at this https://support.cloudbees.com/hc/en-us/articles/218889337-How-to-build-a-job-using-the-REST-API-and-cURL-
Now, to execute this curl from ant/build.xml, use exec task of ant.

Related

Is any any jenkins curl command which return the running logs of the build

I am hitting the curl command which starts the jenkins job, but i also wanted to get the running logs of build is is possible with the help of curl command.
Take a look at
Jenkins REST API to get job and job console log
and
https://serverfault.com/questions/888176/how-to-trigger-jenkins-job-via-curl-command-remotely
Generally, you have to start job get handler and periodically call API
The environment BUILD_URL represents the current build url, thus you can get the current build log as following in job post action
curl -u 'jenkins_user:jenkins_pwd' -k "${BUILD_URL}consoleText"

Trigger another jenkins job execute shell

How to trigger a jenkins job from another freestyle job execute shell section? For pipeline jobs we have groovy which makes it easy.
Two ways to do.
1 - Add a post-build step to build another project
2 - Create a user in jenkins to build remotely jobs (example remoteUser). Create a API TOken for this user. Edit the project to be triggered and make the option “Trigger Builds Remotely”, add an authentication token (IT'S NOT THE TOKEN OF THE USER, YOU CAN GENERATE A NEW FOR THIS).
Now can just use curl to start the job
curl -X POST HTTP://remoteUser:{remoteUser_API_TOKEN}#jenkins.domain/project/my_project/build?token=TOKEN

Establish relationship between two Jenkins Jobs available on different Jenkins server

I am building Jenkins for Test / QA automation scripts, lets name it TEST_JOB. For application, I have application source code Jenkins build, name it DEV_JOB.
My scenario is when DEV_JOB completes execution (successfully), execute TEST_JOB immediately. I am aware about setting up project upstream / downstream [ Build after other projects are built ] to accomplish this task. But here, Problem is DEV_JOB is on different server than TEST_JOB. Due to which, TEST_JOB fails to recognize DEV_JOB.
Now, how would I achieve this scenario?
You can use Jenkins API for remote trigger of Job.
Say you have job on DEV_JOB on JENKINS_1, add a penultimate step(or upstream/downstream project having only this step) which invokes TEST_JOB using remote API call of JENKINS_2 server.
Example command would be
$(curl --user "username:password" "http://JENKINS_2/job/TEST_JOB/buildWithParameters?SOMEPARAMETER=$SOMEPARAMETER")
username:password is a valid user on JENKINS_2.
Avoid using your own account here but rather a 'build trigger' account that only has permissions to start those jobs.

How to trigger a jenkins job remotely which has a list subversion tag as a parameter

I have a requirement where i need to trigger the build jobs remotely using curl command. I am unable to pass the branch/tag name as a parameter to trigger the build.
I used the below command :
& $CURLEXE -k -X POST $dst_job_url --user username:token --data-urlencode json='{"parameters": [{"name":"branch","branch":"branches"}]}'
If i run the above command it was triggers the build for the trunk ( default ).
You omitted the URL, so it's hard to be certain. Jenkins has two urls for building: "build" and "buildWithParameters". If you're not using buildWithParameters, switching to it will probably help.
See:
How to trigger Jenkins builds remotely and to pass parameters

Is there a way to trigger a Jenkins job from "execute shell" of another Jenkins job?

I have three Jenkins jobs. The first job has "execute bash" as a build step. The bash script has if/else statement. And based on this if/else I need to trigger the other two jobs. Is there a way in the "execute shell" to trigger other jobs?
Inside the Execute Shell , you can execute any shell command (including curl).
You can trigger an existing job with curl. e.g.
curl -X POST http://xx.xx.xx.xx:xx/job/jobname/build --user foo:foo_token

Resources