Coder Social home page Coder Social logo

chavaillaz / jenkins-client Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 146 KB

Asynchronous Jenkins client with Jackson supporting multiple HTTP clients.

License: Apache License 2.0

Shell 0.22% Java 99.27% Dockerfile 0.21% Groovy 0.30%
java jenkins asynchronous client

jenkins-client's Introduction

Jenkins Client

Dependency Check Maven Central License

This library allows you to interact with a Jenkins instance and choose which HTTP client to use. It is also easily extendable, allowing you to have custom clients. All requests are performed asynchronously and return a CompletableFuture. The serialization and deserialization of domain objects are performed using Jackson.

Presently, it supports the following HTTP clients:

Note that this library has been tested with a Jenkins instance version 2.426.1.

Installation

The dependency is available in maven central (see badge for version):

<dependency>
    <groupId>com.chavaillaz</groupId>
    <artifactId>jenkins-client</artifactId>
</dependency>

Don't forget to also declare the HTTP client you want to use as a dependency (see below), as it is only indicated as optional in the project, to avoid gathering them all together despite the fact that only one is needed.

Java HTTP client

It does not require any dependency (already in Java).

Apache HTTP client

It requires the following dependency:

<dependency>
    <groupId>org.apache.httpcomponents.client5</groupId>
    <artifactId>httpclient5</artifactId>
    <version>5.2.x</version>
</dependency>

OkHttp client

It requires the following dependency:

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.12.x</version>
</dependency>

Vert.x client

It requires the following dependency:

<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-web-client</artifactId>
    <version>4.5.x</version>
</dependency>

Usage

Features

  • JobApi - Everything for folders, views, jobs and their builds
    • Folders
      • getFolder(Path path)
      • getFolderConfiguration(Path path)
      • createFolder(Path path, String folderName)
      • renameFolder(Path path, String folderName, String newName)
      • deleteFolder(Path path, String folderName)
    • Views
      • getView(Path path, String viewName)
      • getViewConfiguration(Path path, String viewName)
      • createView(Path path, String viewName)
      • updateViewConfiguration(Path path, String viewName, String configXML)
      • deleteView(Path path, String viewName)
    • Jobs
      • getJob(Path path, String jobName)
      • getJobConfiguration(Path path, String jobName)
      • getJobDescription(Path path, String jobName)
      • createJob(Path path, String jobName, String configXML)
      • updateJobConfiguration(Path path, String jobName, String configXML)
      • renameJob(Path path, String jobName, String newName)
      • enableJob(Path path, String jobName)
      • disableJob(Path path, String jobName)
      • deleteJob(Path path, String jobName)
    • Builds
      • getLastBuildNumber(Path path, String jobName)
      • getBuild(Path path, String jobName, int buildNumber)
      • getArtifact(Path path, String jobName, int buildNumber, String artifactPath)
      • getTestReport(Path path, String jobName, int buildNumber)
      • getTestCoverageReport(Path path, String jobName, int buildNumber)
      • getConsoleOutput(Path path, String jobName, int bufferOffset)
      • getConsoleOutput(Path path, String jobName, int buildNumber, int bufferOffset)
      • buildJob(Path path, String jobName)
      • buildJob(Path path, String jobName, Map<Object, Object> properties)
      • stopBuild(Path path, String jobName, int buildNumber)
  • PipelineApi - Everything for pipelines
    • getRunHistory(Path path, String pipelineName, String branchName)
    • getRun(Path path, String pipelineName, String branchName, long buildNumber)
    • getRunPendingActions(Path path, String pipelineName, String branchName, long buildNumber)
    • getRunArtifacts(Path path, String pipelineName, String branchName, long buildNumber)
    • getRunNode(Path path, String pipelineName, String branchName, long buildNumber, String nodeId)
    • getRunNodeLog(Path path, String pipelineName, String branchName, long buildNumber, String nodeId)
  • PluginApi - Everything for plugins
    • getPlugins()
    • getPlugins(Integer depth)
    • installPlugin(String pluginId)
  • QueueApi - Everything for queues
    • getQueueItems()
    • getQueueItem(long queueId)
    • getQueueItemOptional(long queueId)
    • cancelQueueItem(long id)
  • SystemApi - Everything for system management
    • getSystemInfo()
    • getOverallLoad()
    • quietDown()
    • cancelQuietDown()
    • restart()
    • safeRestart()
    • exit()
    • safeExit()
    • reload()
  • UserApi - Everything for users
    • getUser()
    • generateToken(String tokenName)
    • revokeToken(String tokenUuid)

Client instantiation

Instantiate the Jenkins client of your choice by giving your Jenkins instance URL. Depending on your needs, you may also want to add authentication with an access token using withTokenAuthentication or with username and password using withUserAuthentication. If you need to connect via a proxy, you can specify it using withProxy. Below an example for each HTTP client:

JenkinsClient client = JenkinsClient.javaClient("https://jenkins.mycompany.com")
    .withUserAuthentication("myUsername","myPassword")
    .withProxy("http://proxy.mycompany.com:1234");
JenkinsClient client = JenkinsClient.apacheClient("https://jenkins.mycompany.com")
    .withUserAuthentication("myUsername","myPassword")
    .withProxy("http://proxy.mycompany.com:1234");
JenkinsClient client = JenkinsClient.okHttpClient("https://jenkins.mycompany.com")
    .withUserAuthentication("myUsername","myPassword")
    .withProxy("http://proxy.mycompany.com:1234");
JenkinsClient client = JenkinsClient.vertxClient("https://jenkins.mycompany.com")
    .withUserAuthentication("myUsername","myPassword")
    .withProxy("http://proxy.mycompany.com:1234");

From this JenkinsClient you will then be able to get the desired APIs described in the feature chapter.

Iterable results

When requesting a list of elements, the client returns an object encapsulating this list, sometimes with more pieces of information depending on the Jenkins endpoint called. From this object, you can iterate directly on its child elements.

Contributing

If you have a feature request or found a bug, you can:

  • Write an issue
  • Create a pull request

Code style

The code style is based on the default one from IntelliJ, except for the following cases:

Imports

Imports are ordered as follows:

  • All static imports in a block
  • Java non-static imports in a block
  • All non-static imports in a block

A single blank line separates every block. Within each block the imported names appear in alphabetical sort order. Wildcard imports, static or otherwise, are not used.

Arrangements

The attributes of domain classes are ordered alphabetically.

License

This project is under Apache 2.0 License.

jenkins-client's People

Contributors

chavjoh avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.