Jenkins

https://img.shields.io/pypi/v/kpireport-jenkins
pip install kpireport-jenkins

The Jenkins plugin provides both a Datasource for querying the Jenkins API, as well as a View for displaying a summary of job/build statuses. The list of jobs can be filtered to target jobs that are of interest in your reporting.

Datasource

Show/hide example configuration YAML
---
title: CI report

datasources:
  jenkins:
    plugin: jenkins
    args:
      host: jenkins:8080
      user: jenkins_user
      api_token: jenkins_token

views:
  app_build_summary:
    plugin: jenkins.build_summary
    title: Problem application builds
    args:
      filters:
        name: -app
  other_builds:
    plugin: jenkins.build_summary
    title: Other builds
    args:
      filters:
        invert: True
        name: -app

Build summary

jenkins.build_summary

An example showing jobs matching a certain name pattern “*-app”

API

class kpireport_jenkins.datasource.JenkinsDatasource(report, **kwargs)

Bases: kpireport.datasource.Datasource

Provides accessors for listing all jobs and builds from a Jenkins host.

The Jenkins Datasource exposes an RPC-like interface to fetch all jobs, as well as job details for each job. The plugin will call the Jenkins API at the host specified using a username and API token provided as plugin arguments.

host

Jenkins host, e.g. https://jenkins.example.com.

Type

str

user

Jenkins user to authenticate as.

Type

str

api_token

Jenkins user API token to authenticate with.

Type

str

get_all_jobs()

List all jobs on the Jenkins server.

Returns

a DataFrame with columns:

fullname

the full job name (will include folder path components)

url

a URL that resolves to the job on the Jenkins server

Return type

pandas.DataFrame

get_job_info(job_name)

Get a list of builds for a given job, including their statuses.

Parameters

job_name (str) – Full name of the job.

Returns

a DataFrame with columns:

status

the build status, e.g. “SUCCESS” or “FAILURE”

Return type

pandas.DataFrame

query(fn_name, *args, **kwargs)

Query the Datsource for job or build data.

Calls a supported accessor function by name and passthrough any positional and keyword arguments.

Examples:

# Get a list of all jobs in the Jenkins server
datasources.query("jenkins", "get_all_jobs")
# Get detailed information about 'some-job'
datasources.query("jenkins", "get_job_info", "some-job")
Parameters

fn_name (str) – the RPC operation to invoke.

Raises

ValueError – if an invalid RPC operation is requested.

class kpireport_jenkins.build_summary.JenkinsBuildSummary(report: Report, datasources: kpireport.datasource.DatasourceManager, **kwargs)

Bases: kpireport.view.View

Display a list of jobs with their latest build statuses, and health.

Formats

html, md

Parameters
  • datasource (str) – the Datasource ID to query for Jenkins data

  • filters (dict) – optional filters to limit which jobs are rendered in the view. These filters are directly passed to JenkinsBuildFilter.

class kpireport_jenkins.build_summary.JenkinsBuildFilter(name=None, invert=False)

Filters a list of Jenkins jobs/builds by a general criteria

Currently only filtering by name is supported, but this class can be extended in the future to filter on other attributes, such as build status or health.

Parameters
  • name (Union[str, List[str]]) – the list of name filter patterns. These will be compiled as regular expressions. In the case of a single filter, a string can be provided instead of a list.

  • invert (bool) – whether to invert the filter result

filter_job(job)

Checks a job against the current filters

Parameters

job (dict) – the Jenkins job

Return type

bool

Returns

whether the job passes the filters

Changelog

0.0.1

Prelude

Initial release.

New Features

  • Initial release.