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
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")'
Our Jenkins + Bitbucket cloud integration already works and uses a multi-branch pipeline job to notify Bitbucket about the build status of a pull request.
Now I want to enhance it and add preview environments, for example at pr150.testing.company.com so that we can test a live production build before merging. I planned on using docker-compose to dynamically start/stop the preview environments.
Now, Jenkins needs to comment the Bitbucket pull request with the link to the preview environment. I know that the Bitbucket API supports creating pull request comments.
I imagine comments like this:
This example is taken from Jenkins-X
Does any Bitbucket plugin for Jenkins support automatically creating such comments?
Edit: To clarify, a plugin that automatically comments on the pull request would be enough. It's no problem to create the content of the comment on our end.
I couldn't find a plugin but you can execute shell commands as part of the jobs build to do it. Since Jenkins works off commits and not pull requests it's a bit of a faf. You need to get the pull request ID from the branch name using the API first. Using the REST 1.0 API you can do it this way.
BranchName=`echo ${GIT_BRANCH} | sed 's/origin\///'`
PullRequestID=`curl -s --request GET --url '{bitbucket_url}/rest/api/1.0/projects/{project_key}/repos/{repo_key}/pull-requests?State=OPEN&at=refs/heads/'${BranchName}'&direction=OUTGOING' --header 'Content-Type: application/json' -u username:password | sed -n 's/.*"values":\[{"id":\([0-9]*\).*/\1/p'`
echo '{"text": "Here's my comment with hyperlink"}' > comment.json
curl --request POST --url '{bitbucket_url}/rest/api/1.0/projects/{project_key}/repos/{repo_key}/pull-requests/'$PullRequestID'/comments' --header 'Content-Type: application/json' -u username:password -d #comment.json
rm comment.json
Notes:
The remote name might not be origin but something project specific. Check the console log to find it out
Will need changing for 2.0 API but concept should remain the same
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 jenkins Job that do two steps.
1) Get source code from GIT
2) Run the source code analisys using SONAR-RUNNER
The Job works fine and I'd like to copy/create a similar Job.
I tried to create a new Job using the command: curl -s --data-binary #config.xml -H "Content-Type: application/xml" -X POST http://localhost:8080/createItem?name=SONAR-NEW
It does create a new Job, however the SONAR-RUNNER part is empty and if I ran the build it doesn't make the SONAR part. The funny thing is that if I check the config.xml generated the SONAR-RUNNER configuration part is there.
The same thing happens if I try to copy the JOB, I tried it using:
1) jenkins-cli, or
2) curl --data "name=NEWJOBNAME&mode=copy&from=SONAR" -X POST http://localhost:8080/createItem
If I have a different build step, for example a "Execute SHell", I am able to copy/create the JOB.
So my question is how can I create or copy a JOB that as a build step using "Execute SonarQube Scanner"
I've to perform an HTTP post of an artifact (Jenkins build) to an Internet website. Nevertheless my Company has got a proxy in front of Jenkins.
Does anybody know how to authenticate against an http proxy during a Jenkins task ?
Thanks and Regards
Just add the following lines in execute shell field of Post-build Actions :-
curl -x <proxy_host:proxy_port> -X POST <url_of_website> --data-binary <your_artifact_location>