Jenkins Remote access API Example | Jenkins Tutorial

Jenkins Remote access API Example
Jenkins provides machine-consumable remote access API to its functionalities. Currently it comes in three flavors:
JSON with JSONP support
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, visiting 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., then go to 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.
Tagged : / / / / / / /

Simple Ant Example – clean, prepare, and compile tasks


Sample Ant clean, prepare, and compile tasks

<target name=”clean”>
<echo>=== CLEAN ===</echo>
<delete failonerror=”false”>
<fileset dir=”${dest.dir}” includes=”**/*”/>
<delete dir=”${temp.dir}” />

<target name=”prepare” depends=”clean”>
<echo>=== PREPARE ===</echo>
<mkdir dir=”${dest.dir}” />
<mkdir dir=”${temp.dir}” />
<mkdir dir=”${temp.dir.lib}” />
<mkdir dir=”${temp.dir.meta-inf}” />
<mkdir dir=”${temp.dir.web-inf}” />
<mkdir dir=”${temp.dir.classes}” />

<target name=”compile” depends=”prepare”>
<echo>=== COMPILE ===</echo>
<echo>Compiling ${src.dir} files …</echo>
<javac debug=”on” srcdir=”${src.dir}” destdir=”${temp.dir.classes}” includes=”**/*”>
<classpath refid=”build.class.path” />

<!– compile files on the src-tests path –>
<echo>Compiling ${src.tests.dir} files …</echo>
<javac debug=”on” srcdir=”${src.tests.dir}” destdir=”${temp.dir.classes}” includes=”com/**”>
<classpath refid=”build.class.path” />

Tagged : / / / / / / / / / / / / / / / /

Ant’s built-in properties – Ant Properties Guide


This is a simple example that illustrates how to find the basedir name, file name, project name, ant version, java version, operating system name, ant home directory name, java home directory name, user home directory name and user name. Ant provides you with certain built-in properties that you may find useful during your build process. The following table shows the property name and it’s description.


Ant’s built-in properties:

Property                                                              Description


ant.file                                                                  The absolute path of the build file                                            The name of the project as set in the <project> element’s name attribute.


ant.home                                                            The root directory of ant


ant.version                                                         The version of this ant installation. This is not just the version number and includes information such as the compilation date.                                               The version of the java that ant uses


basedir                                                                 The absolute path of the project                                                              Operating system name


java.home                                                          Java home directory name


user.home                                                          User directory name                                                          User name                         



Example Program:

<?xml version=”1.0″?>


<project name=”AntProperties” default=”echo” basedir=”.”>


  <target name=”echo”>

  <echo message=”The operating system is: ${}”/> 


  <!– absolute path of the project. –>

  <echo message=”The home path is: ${basedir}”/>


  <!– absolute path of the build file. –>

  <echo message=”The file name is: ${ant.file}”/>


  <!– root directory of ant. –>

  <echo message=”The Project name is: ${}”/>

  <echo message=”The Ant home directory is: ${ant.home}”/>

  <echo message=”The Ant version is: ${ant.version}”/>

  <echo message=”The Java version is: ${}”/>


  <!– System properties. –>

  <echo message=”The Java home directory is: ${java.home}”/>

  <echo message=”The User home directory is: ${user.home}”/>

  <echo message=”The User name is: ${}”/>





Tagged : / / / / / / / / / / / / /