Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

API Basics

Maxime Malgorn edited this page Feb 8, 2019 · 4 revisions

Initialization

First, you have to construct the Jenkins object with at least 1 parameter.

  • Root URL where the Jenkins server is running.
  • Username of the account to connect with. (optional, for a private instance)
  • API token associated with the account. (optional, for a private instance)

Usage:

<?php
require "./vendor/autoload.php";

use \Utarwyn\Jenkins\Jenkins;

$jenkins = new Jenkins("https://myjenkinsserver.com", "username", "api_token");
?>

Obtain your Jenkins API Token

  1. Go to the root of your Jenkins server and log in.
  2. Click on your name in the upper right corner to bring up your user page.
  3. Click on Configure in the left side menu.
  4. Click the Show API Token... button.

You can also change your API token by clicking on the Change API Token button.

Get server information

All server information are automatically stored in the Jenkins object when connecting.

Method name Description Parameters Return type
getDescription Main description of the instance - string
getMode Constants that control how Jenkins allocates jobs to agents - string
getNodeDescription Human-readable description of the main node - string
getNodeName Name of the main node - string
getNumExecutors Number of executors - int
getQueue Construction queue of the main node - Queue
getPluginManager Plugin manager of the Jenkins instance - PluginManager
getProjects List of all projects managed - Project[]
getProjectsNb Number of projects managed - int
getProject Get a specific project by its name name: string Project
getViews List all views - View[]
getView Get a specific view by its name name: string View
getSlaveAgentPort Get port of the slave agent - int
getVersion Version of the Jenkins server - string
getUserManager User Manager of the jenkins instance - UserManager
isQuietingDown True if Jenkins is quieting down - bool
isUsingCrumbs True if all POST requests would have to have crumb in it - bool
isUsingSecurity True if there is some security restrictions in place - bool

An example:

// Get the version of the Jenkins server!
$version = $jenkins->getVersion();
// Get the construction queue
$queue = $jenkins->getQueue();
Clone this wiki locally