Im Trying to do the following:
Job X (Jenkins Job) on server A running a Groovy script and the output of that script is a string.
My goal is to pass this string to job Y (Jenkins Job) on server B.
What is the best way to pass this string to a remote Jenkins Job?
Thanks
You can use any one of the two options:
Option 1: Remote Trigger Plugin
Option 2: Using API
curl -v -X POST jenkins_url/job/job_name/buildWithParameters
--data token=your_token
--user jenkins_user_email:jenkins_user_password
--data-urlencode json= '{"parameter1":"value1", "parameter2":"value2"}'
Related
I need to use it in Jenkins pipeline without using the plugin.
Is there a way to fetch artifact from JFrog using API?
I have a Jenkins job where I have to draft a shell script which fetches the artifact from jfrog. If it was in Jenkins-file I would have used the plug-in. Is there a API way of doing it so that I can put that API in my shell script and run it from Jenkins pipeline?
You can use the AQL(Artifactory Query Language) to get the artifacts through api. Like this
curl -u<user>:<password> -X POST -k -H 'Content-Type:text/plain' -i https://<artifactory_host>/artifactory/api/search/aql
If you want to filter the result then you can add condtions to api by passing json
curl -u<user>:<password> -X POST -k -H 'Content-Type:text/plain' -i https://<artifactory_host>/artifactory/api/search/aql --data 'items.find({"name" : {"$match":"*.jar"}}).include("name")'
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"
We are currently using Bamboo in our company but need Jenkins for a specific task the Bamboo machine is not capable of. Is it possible to set up a Jenkins build job and trigger it remotely out of Bamboo, so not everybody has to figure out the new interface?
You can run Jenkins jobs remotely, even jobs that require parameters, by means of the REST API, find more information in the documentation here.
You can add a Bamboo task in your job to run a shell script that actually consumes the Jenkins API in that case you might need curl to be installed (in case of using a python script you can use requests, etc)
Example: To just run a Jenkins job that does not requires any params:
curl -X POST --user USER:TOKEN JENKINS_URL/job/JOBNAME/build
Example: To run a Jenkins job that requires params:
curl -X POST JENKINS_URL/job/JOB_NAME/build \
--user USER:TOKEN \
--data-urlencode json='{"parameter": [{"name":"id", "value":"123"}, {"name":"verbosity", "value":"high"}]}'
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
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.