public class JenkinsAPI extends Object
 Usage: 
 Set the following system properties :
 
Pass them to the JVM :
-Duser.name=[user_name]or set them in your Java code :
 System.setProperty("user.name", "[user_name]");
 
 Instantiate API and use its methods :
 
 JenkinsAPI api = new JenkinsAPI();
 api.enableJob("myjob");
 ...
 
 Start a job and monitor it :
 
 String location = api.startJob("myjob");
 int buildNumber = api.getBuildNumber(location);
 api.monitorJob("myjob", buildNumber);
 | Modifier and Type | Class and Description | 
|---|---|
| static class  | JenkinsAPI.FileParameterRepresents a file parameter. | 
| class  | JenkinsAPI.LogThreadLogs a message at a given time interval. | 
| static class  | JenkinsAPI.ParameterRepresents a parameter of the Jenkins job. | 
| static class  | JenkinsAPI.StringParameterRepresents a string parameter. | 
| Constructor and Description | 
|---|
| JenkinsAPI()Constructor of the class. | 
| JenkinsAPI(CloseableHttpClient client)Constructor of the class. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | deleteJob(String jobName)Deletes a job. | 
| void | disableJob(String jobName)Disables a job. | 
| void | enableJob(String jobName)Enables a job. | 
| String[] | getAllJobs(String text)Get all jobs which name contains the given text. | 
| int | getBuildNumber(String location)Returns the number of the build of the given queued item location. | 
| byte[] | getJobConfigXML(String jobName)Gets the  config.xmlof a job. | 
| List<Integer> | getRunningBuildNumbers(String jobName)Returns a list of the running build numbers. | 
| protected org.w3c.dom.Document | getXmlDocument(InputStream is) | 
| boolean | jobExists(String jobName)Tells whether a job exist or not. | 
| void | monitorJob(String jobName,
          int buildNumber)Monitors the build of the given job that has the given build number. | 
| protected HttpURLConnection | newHttpURLConnection(String path,
                    String action) | 
| void | newJob(String jobName,
      byte[] configXML)Creates a new job with the given  config.xml. | 
| void | renameJob(String jobName,
         String jobNewName)Renames a job | 
| String | startJob(String jobName,
        List<JenkinsAPI.Parameter> parameters)Starts the job that has the given name with the given files and parameters. | 
| void | stopRunningBuild(String jobName)Stops all the running builds for the given job. | 
| void | storeJobConfigXML(String jobName,
                 byte[] configXML)Stores the  config.xmlof a job. | 
public JenkinsAPI()
public JenkinsAPI(CloseableHttpClient client)
client - The CloseableHttpClient used to communicate with the Jenkins server.public void deleteJob(String jobName)
jobName - the job to delete.public void disableJob(String jobName)
jobName - the job to disablepublic void enableJob(String jobName)
jobName - the job to enablepublic String[] getAllJobs(String text)
text - must not contains white spacespublic int getBuildNumber(String location)
location - The location of the queued item.public byte[] getJobConfigXML(String jobName)
config.xml of a job.jobName - the job to get the configurationconfig.xml content (UTF-8 encoded)public List<Integer> getRunningBuildNumbers(String jobName)
jobName - The job name.protected org.w3c.dom.Document getXmlDocument(InputStream is)
public boolean jobExists(String jobName)
jobName - the job to testpublic void monitorJob(String jobName, int buildNumber)
jobName - The name of the job.buildNumber - The number of the build.protected HttpURLConnection newHttpURLConnection(String path, String action) throws IOException
IOExceptionpublic void newJob(String jobName, byte[] configXML)
config.xml.jobName - the job to createconfigXML - UTF-8 encodedpublic void renameJob(String jobName, String jobNewName)
jobName - the job to renamejobNewName - the new job namepublic String startJob(String jobName, List<JenkinsAPI.Parameter> parameters)
jobName - The name of the job.parameters - The parameters for the job.public void stopRunningBuild(String jobName)
jobName - the job.public void storeJobConfigXML(String jobName, byte[] configXML)
config.xml of a job.jobName - the job to store the configurationconfigXML - UTF-8 encoded