cdancy / jenkins-rest

Java client, built on top of jclouds, for working with Jenkins REST API
Apache License 2.0
387 stars 173 forks source link
cd cdcd ci client continuous-integration devops java jclouds jenkins jenkins-rest rest rest-api

Maven Central Stack Overflow

jenkins-rest

Java client is built on the top of jclouds for working with Jenkins REST API.

Setup

Client's can be built like so:

JenkinsClient client = JenkinsClient.builder()
.endPoint("http://127.0.0.1:8080") // Optional. Defaults to http://127.0.0.1:8080
.credentials("admin:password") // Optional.
.build();

SystemInfo systemInfo = client.api().systemApi().systemInfo();
assertTrue(systemInfo.jenkinsVersion().equals("1.642.4"));

Latest release

Can be found in maven like so:

<dependency>
  <groupId>io.github.cdancy</groupId>
  <artifactId>jenkins-rest</artifactId>
  <version>X.Y.Z</version>
  <classifier>sources|tests|javadoc|all</classifier> (Optional)
</dependency>

Documentation

Property based setup

Client instances do NOT need to supply the endPoint or credentials as a part of instantiating the JenkinsClient object. Instead one can supply them through system properties, environment variables, or a combination of the two. System properties will be searched first and if not found, will attempt to query the environment.

Setting the endpoint can be done with any of the following (searched in order):

When none is found, the endpoint is set to http://localhost:8080.

Setting the credentials can be done with any of the following (searched in order):

When none is found, no authentication is used (anonymous).

Credentials

jenkins-rest credentials can take 1 of 3 forms:

The Jenkins crumb is automatically requested when POSTing using the anonymous and the username:password authentication methods. It is not requested when you use the apiToken as it is not needed in this case. For more details, see

Examples

The mock and live tests provide many examples that you can use in your own code.

Components

Testing

Running mock tests can be done like so:

./gradlew clean build mockTest

Running integration tests require an existing jenkins instance which can be obtained with docker:

    docker build -t jenkins-rest/jenkins src/main/docker
    docker run -d --rm -p 8080:8080 --name jenkins-rest jenkins-rest/jenkins
./gradlew clean build integTest 

Integration tests settings

If you use the provided docker instance, there is no other preparation necessary. If you wish to run integration tests against your own Jenkins server, the requirements are outlined in the next section.

Jenkins instance requirements

This project provides instructions to setup a pre-configured Docker container

Integration tests configuration

Running integration tests from within your IDE

Additional Resources