Jenkins Remote access API Example
Jenkins provides machine-consumable remote access API to its functionalities. Currently it comes in three flavors:
XML
JSON with JSONP support
Python
Remote access API is offered in a REST-like style. That is, there is no single entry point for all features, and instead they are available under the “…/api/” URL where “…” portion is the data that it acts on.
For example, if your Jenkins installation sits at http://ci.jruby.org/, visiting http://ci.jruby.org/api/ will show just the top-level API features available – primarily a listing of the configured jobs for this Jenkins instance.
Or if you want to access information about a particular build, e.g. http://ci.jruby.org/job/jruby-base/lastSuccessfulBuild/, then go to http://ci.jruby.org/job/jruby-base/lastSuccessfulBuild/api/ and you’ll see the list of functionalities for that build.
Remote API can be used to do things like these:
Retrieve information from Jenkins for programmatic consumption.
trigger a new build
create/copy jobs
Jobs with parameters, Also see Parameterized Build.
Simple example – sending “String Parameters”:
curl -X POST JENKINS_URL/job/JOB_NAME/build \
–data token=TOKEN \
–data-urlencode json='{“parameter”: [{“name”:”id”, “value”:”123″}, {“name”:”verbosity”, “value”:”high”}]}’
Check Jenkins Job Status via REST API
job_status=`curl https://jenkins/view/job/other-job/lastBuild/api/json | grep “\”result\”:\”SUCCESS\””`
if [ -n "$job_status" ] then # Run your script commands here else echo "BUILD FAILURE: Other build is unsuccessful or status could not be obtained." exit 1 fi
How to restart Jenkins manually?
To restart Jenkins manually, you can use either of the following commands:
(jenkins_url)/safeRestart – Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete.
(jenkins_url)/restart – Forces a restart without waiting for builds to complete.
Reference
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-1
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-2
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-3
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-4
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-5
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-6
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-7
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-8
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-9
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-10
Jenkins Complete Referenece by Rajesh Kumar in 2020 – Session-11
Latest posts by Rajesh Kumar (see all)
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024