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 was trying to find a method to add plugins to Jenkins programmatically and found this answer useful. It shows a method using the following curl command and restarting Jenkins after that.
curl -X POST -d '<jenkins><install plugin="plugin-name#version" /></jenkins>' --header 'Content-Type: text/xml' http://localhost:8080/pluginManager/installNecessaryPlugins
It worked successfully for many plugins, but it failed for some plugins like Pipeline and Amazon EC2. Below is the command I used to install Pipeline plugin.
curl -X POST -d '<jenkins><install plugin="Pipeline#2.6" /></jenkins>' --header 'Content-Type: text/xml' http://localhost:8080/pluginManager/installNecessaryPlugins
How can I fix this?
You need to specify plugin-id in request.
You can find your plugin on https://plugins.jenkins.io and get plugin-id from description.
For example Declarative pipeline plugin (https://plugins.jenkins.io/pipeline-model-definition) has id pipeline-model-definition
Pipeline: Declarative1.3.9
Minimum Jenkins requirement: 2.150.1
ID: pipeline-model-definition
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 am currently using Gerrit server side hook script to trigger Jenkins job to run whenever there is a new patch set submitted to Gerrit server. I do not use Jenkins Gerrit event plugin because I do not want to have any Gerrit missed event happen.
However, I face some difficulties on how to pass the rating back to Gerrit server if the Jenkins job run successfully or fail. How can I achieve this result? Is there anyone trying to achieve the same thing as me? Please advise.
Thanks in advance
You can make a script to vote on Gerrit using the REST API. For example, the following command will set Code-Review=1:
curl --request POST --user USER:PASS --data #- --header Content-Type:application/json https://GERRIT-SERVER/a/changes/CHANGE-NUMBER/revisions/PATCHSET-NUMBER/review <<EOF
{
"message": "So far so good",
"labels": {
"Code-Review": 1,
}
}
EOF
See more info about the REST API here.
I am new to Jenkins, and I'm not sure if this is possible, but I would like to set up a web interface where somebody could click "Start Job" and this will tell Jenkins to start a particular build job.
Does Jenkins have a webservice that would allow such a thing? If so, what would be a simple example?
Here is a link to the documentation: Jenkins Remote Access API.
Check out the Submitting jobs section.
In your job configuration you setup a token and then create a POST request to JENKINS_URL/job/JOBNAME/build?token=TOKEN. That's probably the most basic usage.
Jenkins has support for parameterized build as well.
So, if you want to pass parameters for configurable build generation, you can pass them by posting it while invoking Jenkins build request with http://YOURHOST/jenkins/job/PROJECTNAME/buildWithParameters.
Aha, I found it in the documentation. So simple:
http://YOURHOST/jenkins/job/PROJECTNAME/build
I needed to add parameters and I wanted to do it over https. It took me a while but the following worked for me:
curl --request POST --url 'https://HOST_NAME/job/JOB_NAME/buildWithParameters?token=TOKEN' --header 'cache-control: no-cache' --header 'content-type: application/x-www-form-urlencoded' --data 'name1=value1&name2=value2'
Use:
http://some server/job/myjob/buildWithParameters?token=TOKEN&PARAMETER=Value
You can take a look at this documentation: Parameterized Build
curl -H POST http://USERNAME:PASSWORD#JENKINS_HOST:PORT/job/JOB_NAME/build?token=YOUR_TOKEN
Set YOUR_TOKEN at job configuration -> build triggers -> Trigger builds remotely.
There is a good sample of using the above API from Python. The project is called Python Jenkins, and you may find it here: link
Jenkins has a documented REST API. You can make your little web service invoke it.
With curl if you have multiple arguments to pass like a token and a parameter you might have to quote on Linux shell:
curl -H POST "http://USERNAME:PASSWORD#JENKINS_HOST:PORT/job/JOB_NAME/build?token=YOUR_TOKEN&PARAMETER=VALUE"
Install Generic Webhook Trigger plugin.
Select generic webhook trigger in build trigger actions. Generate a random string and paste in token.
Now your job can be triggered with a http request to the following url.
http://JENKINS_URL/generic-webhook-trigger/invoke?token=TOKEN_VALUE
replace your jenkins url and token value