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")'
Related
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
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"}]}'
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"}'
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