Skip to content

Commit 56b1d57

Browse files
committed
initial version of Jenkins API client
0 parents  commit 56b1d57

15 files changed

+813
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.iml
2+
/.idea
3+
/target

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2012 Cosmin Stejerean
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# jenkins-client
2+
3+
A Java client for the Jenkins API
4+
5+
## Getting Started
6+
7+
To get started add the following dependency to your project
8+
9+
```xml
10+
<dependency>
11+
<groupId>com.offbytwo.jenkins</groupId>
12+
<artifactId>jenkins-client</artifactId>
13+
<version>0.1.0-SNAPSHOT</version>
14+
</dependency>
15+
```
16+
17+
## Usage
18+
19+
The `com.offbytwo.jenkins.JenkinsServer` class provides the main entry
20+
point into the API. You can create a reference to the Jenkins server
21+
given its location and (optionally) a username and password/token.
22+
23+
```java
24+
JenkinsServer jenkins = new JenkinsServer(new URI("http://localhost:8080/jenkins"), "admin", "password")
25+
```
26+
27+
At the top level you can access all of the currently defined jobs
28+
29+
```java
30+
List<Job> jobs = jenkins.getJobs()
31+
```
32+
33+
The Job class provides only summary information (name and url). You can retrieve details as follows
34+
35+
```java
36+
JobWithDetails job = jobs.get(0).details()
37+
```
38+
39+
The `JobWithDetails` class provides you with access to the list of
40+
builds (and related information such as the first, last, successful,
41+
etc) and upstream and downstream projects.
42+
43+
## License
44+
45+
Copyright (C) 2012, Cosmin Stejerean.
46+
47+
Distributed under the MIT license: http://opensource.org/licenses/MIT

pom.xml

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2012 Cosmin Stejerean.
4+
~
5+
~ Distributed under the MIT license: http://opensource.org/licenses/MIT
6+
-->
7+
8+
<project xmlns="http://maven.apache.org/POM/4.0.0"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<name>Jenkins Client</name>
14+
<url>http://github.com/cosmin/jenkins-client</url>
15+
<description>A Jenkins API client for Java</description>
16+
17+
<groupId>com.offbytwo.jenkins</groupId>
18+
<artifactId>jenkins-client</artifactId>
19+
<version>0.1.0-SNAPSHOT</version>
20+
<packaging>jar</packaging>
21+
22+
<parent>
23+
<groupId>org.sonatype.oss</groupId>
24+
<artifactId>oss-parent</artifactId>
25+
<version>7</version>
26+
</parent>
27+
28+
<properties>
29+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30+
</properties>
31+
32+
<licenses>
33+
<license>
34+
<name>MIT License</name>
35+
<url>http://opensource.org/licenses/MIT</url>
36+
</license>
37+
</licenses>
38+
39+
<developers>
40+
<developer>
41+
<name>Cosmin Stejerean</name>
42+
<email>[email protected]</email>
43+
<url>http://offbytwo.com</url>
44+
</developer>
45+
</developers>
46+
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.apache.httpcomponents</groupId>
50+
<artifactId>httpclient</artifactId>
51+
<version>4.2.2</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.codehaus.jackson</groupId>
55+
<artifactId>jackson-mapper-asl</artifactId>
56+
<version>1.9.11</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.google.guava</groupId>
60+
<artifactId>guava</artifactId>
61+
<version>13.0.1</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>junit</groupId>
65+
<artifactId>junit</artifactId>
66+
<version>4.11</version>
67+
<scope>test</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.mockito</groupId>
71+
<artifactId>mockito-all</artifactId>
72+
<version>1.9.5</version>
73+
<scope>test</scope>
74+
</dependency>
75+
</dependencies>
76+
77+
<build>
78+
<plugins>
79+
<plugin>
80+
<groupId>org.apache.maven.plugins</groupId>
81+
<artifactId>maven-jar-plugin</artifactId>
82+
<version>2.4</version>
83+
<inherited>true</inherited>
84+
<configuration>
85+
<archive>
86+
<manifest>
87+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
88+
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
89+
</manifest>
90+
</archive>
91+
</configuration>
92+
</plugin>
93+
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-source-plugin</artifactId>
97+
<version>2.2.1</version>
98+
<executions>
99+
<execution>
100+
<id>attach-sources</id>
101+
<goals>
102+
<goal>jar</goal>
103+
</goals>
104+
</execution>
105+
</executions>
106+
</plugin>
107+
108+
<plugin>
109+
<groupId>org.apache.maven.plugins</groupId>
110+
<artifactId>maven-javadoc-plugin</artifactId>
111+
<version>2.9</version>
112+
<executions>
113+
<execution>
114+
<id>attach-javadocs</id>
115+
<goals>
116+
<goal>jar</goal>
117+
</goals>
118+
</execution>
119+
</executions>
120+
</plugin>
121+
</plugins>
122+
</build>
123+
124+
<profiles>
125+
<profile>
126+
<id>release</id>
127+
<activation>
128+
<property>
129+
<name>performRelease</name>
130+
<value>true</value>
131+
</property>
132+
</activation>
133+
<build>
134+
<plugins>
135+
<plugin>
136+
<groupId>org.apache.maven.plugins</groupId>
137+
<artifactId>maven-gpg-plugin</artifactId>
138+
<version>1.4</version>
139+
<executions>
140+
<execution>
141+
<id>sign-artifacts</id>
142+
<phase>verify</phase>
143+
<goals>
144+
<goal>sign</goal>
145+
</goals>
146+
</execution>
147+
</executions>
148+
</plugin>
149+
</plugins>
150+
</build>
151+
</profile>
152+
</profiles>
153+
154+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2012 Cosmin Stejerean.
3+
*
4+
* Distributed under the MIT license: http://opensource.org/licenses/MIT
5+
*/
6+
7+
package com.offbytwo.jenkins;
8+
9+
import com.offbytwo.jenkins.client.JenkinsHttpClient;
10+
import com.offbytwo.jenkins.model.Job;
11+
import com.offbytwo.jenkins.model.MainView;
12+
13+
import java.io.IOException;
14+
import java.net.URI;
15+
import java.util.List;
16+
17+
/**
18+
* The main starting point for interacting with a Jenkins server.
19+
*/
20+
public class JenkinsServer {
21+
JenkinsHttpClient client;
22+
23+
/**
24+
* Create a new Jenkins server reference given only the server address
25+
*
26+
* @param serverUri address of jenkins server (ex. http://localhost:8080/jenkins)
27+
*/
28+
public JenkinsServer(URI serverUri) {
29+
this(new JenkinsHttpClient(serverUri));
30+
}
31+
32+
/**
33+
* Create a new Jenkins server reference given the address and credentials
34+
*
35+
* @param serverUri address of jenkins server (ex. http://localhost:8080/jenkins)
36+
* @param username username to use when connecting
37+
* @param passwordOrToken password (not recommended) or token (recommended)
38+
*/
39+
public JenkinsServer(URI serverUri, String username, String passwordOrToken) {
40+
this(new JenkinsHttpClient(serverUri, username, passwordOrToken));
41+
}
42+
43+
/**
44+
* Create a new Jenkins server directly from an HTTP client (ADVANCED)
45+
*
46+
* @param client Specialized client to use.
47+
*/
48+
public JenkinsServer(JenkinsHttpClient client) {
49+
this.client = client;
50+
}
51+
52+
/**
53+
* Get a list of all the defined jobs on the server (at the summary level)
54+
*
55+
* @return list of defined jobs (summary level, for details @see Job#details
56+
* @throws IOException
57+
*/
58+
public List<Job> getJobs() throws IOException {
59+
return client.get("/", MainView.class).getJobs();
60+
}
61+
62+
63+
}

0 commit comments

Comments
 (0)