Jenkins behind a Proxy - jenkins

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>

Related

Fetch Jfrog artifact through API in Jenkins job

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")'

Passing parameters between local and remote jenkins jobs

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"}'

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

how to post rating back from Jenkins to Gerrit server without using of Gerrit plugin

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.

Calling a Jenkins build from outside of Jenkins?

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

Resources