smithers

Async Jenkins API client for browsers and node

Usage no npm install needed!

<script type="module">
  import smithers from 'https://cdn.skypack.dev/smithers';
</script>

README

Smithers

Async Jenkins API client for browsers and node

npm version Build Status Coverage Status dependencies Status devDependencies Status

Note: This package is under active development and while the version is less than 1.x.x all releases should be treated as containing breaking changes.

Install

$ npm install --save smithers

Usage

Setup

Basic setup - no authentication (config optional)

import Smithers from 'smithers';

const smithers = new Smithers('https://jenkinsurl.com', config);

Username & password/token auth (config.auth required)

import Smithers from 'smithers';

const smithers = new Smithers('https://jenkinsurl.com', {
    auth: {
        username: 'username',
        password: 'password/token'
    }
});

Configuration

Configuration can be either passed when Smithers is instantiated or when a method is called. The configuration is forwarded to the axios calls so look at the axios documentation to see the different options.

  • crumbIssuer Boolean default=false: Enables CSRF crumb support for post requests
  • timeout Number default=5000: Request timeout in milliseconds

Methods

Note: These examples are using async/await but work perfectly with .then and .catch as well

getInfo()

  • config Object optional

Retrieves all data from the /api/json endpoint.

await smithers.getInfo([config]);

getJobInfo()

  • jobName String required
  • config Object optional

Retrieves all data from a specific job

await smithers.getJobInfo(jobName, [config]);

startBuild()

  • jobName String required
  • config Object optional

Triggers a build for the specific job

await smithers.startBuild(jobName, [config]);

stopBuild()

  • jobName String required
  • buildNumber Number required
  • config Object optional

Stops the build of a specifc job

await smithers.stopBuild(jobName, buildNumber, [config]);

getLastBuild()

  • jobName String required
  • config Object optional

Retrieves all data from the latest build of a specifc job

await smithers.getLastBuild(jobName, [config]);

getLastSuccessfulBuild()

  • jobName String required
  • config Object optional

Retrieves all data from the latest successful build of a specifc job

await smithers.getLastSuccessfulBuild(jobName, [config]);

getLastStableBuild()

  • jobName String required
  • config Object optional

Retrieves all data from the latest stable build of a specifc job

await smithers.getLastStableBuild(jobName, [config]);

getLastUnsuccessfulBuild()

  • jobName String required
  • config Object optional

Retrieves all data from the latest unsuccessful build of a specifc job

await smithers.getLastUnsuccessfulBuild(jobName, [config]);

getLastFailedBuild()

  • jobName String required
  • config Object optional

Retrieves all data from the latest unsuccessful build of a specifc job

await smithers.getLastFailedBuild(jobName, [config]);

getSpecificBuild()

  • jobName String required
  • buildNumber Number required
  • config Object optional

Retrieves all data for a specific build of a specifc job

await smithers.getSpecificBuild(jobName, buildNumber, [config]);

getConfigXML()

  • jobName String required
  • config Object optional

Retrieves the XML config of a specifc job

await smithers.getConfigXML(jobName, [config]);

getOverallLoad()

  • config Object optional

Retrieves statistics of the entire system (busy executors, queue length, etc...)

await smithers.getOverallLoad([config]);

getQueue()

  • config Object optional

Retrieves all data about the current queue

await smithers.getQueue([config]);

getView()

  • viewName String default='All' optional
  • config Object optional

Retrieves all data about a specific view or the default view of 'All'

await smithers.getView(viewName, [config]);

restart()

  • config Object optional

Restarts Jenkins

await smithers.restart([config]);

safeRestart()

  • config Object optional

Restarts Jenkins once no jobs are running

await smithers.safeRestart([config]);

startQuietDown()

  • config Object optional

Starts "quiet down" mode

await smithers.startQuietDown([config]);

stopQuietDown()

  • config Object optional

Stops "quiet down" mode

await smithers.stopQuietDown([config]);

getWhoAmI()

  • config Object optional

Retrieves user details

await smithers.getWhoAmI([config]);

getUser()

  • user String required
  • config Object optional

Retrieves all data about a specific user

await smithers.getUser(user, [config]);