Skip to main content

A Python API for accessing resources on a Jenkins continuous-integration server.

Project description

https://badge.fury.io/py/jenkinsapi.png

Installation

pip install jenkinsapi

Logging

JenkinsAPI emits request/response debug logs when enabled. You can opt in with the environment variable or by calling the helper:

export JENKINSAPI_LOG_LEVEL=DEBUG
from jenkinsapi.utils.logging import configure_logging

configure_logging("INFO")

About this library

Jenkins is the market leading continuous integration system.

Jenkins (and its predecessor Hudson) are useful projects for automating common development tasks (e.g. unit-testing, production batches) - but they are somewhat Java-centric.

Jenkinsapi makes scripting Jenkins tasks a breeze by wrapping the REST api into familiar python objects.

Here is a list of some of the most commonly used functionality

  • Add, remove, and query Jenkins jobs

  • Control pipeline execution
    • Query the results of a completed build

    • Block until jobs are complete or run jobs asyncronously

    • Get objects representing the latest builds of a job

  • Artifact management
    • Search for artifacts by simple criteria

    • Install artifacts to custom-specified directory structures

  • Search for builds by source code revision

  • Create, destroy, and monitor
    • Build nodes (Webstart and SSH slaves)

    • Views (including nested views using NestedViews Jenkins plugin)

    • Credentials (username/password and ssh key)

  • Authentication support for username and password

  • Manage jenkins and plugin installation

Full library capabilities are outlined in the Documentation

Get details of jobs running on Jenkins server

"""Get job details of each job that is running on the Jenkins instance"""
def get_job_details():
    # Refer Example #1 for definition of function 'get_server_instance'
    server = get_server_instance()
    for job_name, job_instance in server.get_jobs():
        print 'Job Name:%s' % (job_instance.name)
        print 'Job Description:%s' % (job_instance.get_description())
        print 'Is Job running:%s' % (job_instance.is_running())
        print 'Is Job enabled:%s' % (job_instance.is_enabled())

Disable/Enable a Jenkins Job

def disable_job():
    """Disable a Jenkins job"""
    # Refer Example #1 for definition of function 'get_server_instance'
    server = get_server_instance()
    job_name = 'nightly-build-job'
    if (server.has_job(job_name)):
        job_instance = server.get_job(job_name)
        job_instance.disable()
        print 'Name:%s,Is Job Enabled ?:%s' % (job_name,job_instance.is_enabled())

Use the call job_instance.enable() to enable a Jenkins Job.

Creating jobs in folders

When using the Folders plugin, you can pass folder paths directly:

jenkins.create_job("folder1/folder2/job-name", config_xml)
jenkins.create_job("/job/folder1/job/folder2/job-name", config_xml)

Known issues

  • Job deletion operations fail unless Cross-Site scripting protection is disabled.

For other issues, please refer to the support URL

Development

  • Make sure that you have Java installed. Jenkins will be automatically downloaded and started during tests.

  • Create virtual environment for development

  • Install package in development mode

uv sync
  • Make your changes, write tests and check your code

uv run pytest -sv

Python versions

The project has been tested against Python versions:

  • 3.9 - 3.14

Jenkins versions

Project tested on both stable (LTS) and latest Jenkins versions.

Project Contributors

Please do not contact these contributors directly for support questions! Use the GitHub tracker instead.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jenkinsapi-0.3.22.tar.gz (437.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jenkinsapi-0.3.22-py3-none-any.whl (78.3 kB view details)

Uploaded Python 3

File details

Details for the file jenkinsapi-0.3.22.tar.gz.

File metadata

  • Download URL: jenkinsapi-0.3.22.tar.gz
  • Upload date:
  • Size: 437.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jenkinsapi-0.3.22.tar.gz
Algorithm Hash digest
SHA256 e24868353cb63a1aa0d1f94e44c167c03ce35a7785595db66f8c67e65f5a003e
MD5 5cb6de7e58b4414b1b7f2884069f47ca
BLAKE2b-256 098b137b39461a48735ba753d51dccc96815a59746bf4c91a2e7600e2e827912

See more details on using hashes here.

Provenance

The following attestation bundles were made for jenkinsapi-0.3.22.tar.gz:

Publisher: release.yml on pycontribs/jenkinsapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jenkinsapi-0.3.22-py3-none-any.whl.

File metadata

  • Download URL: jenkinsapi-0.3.22-py3-none-any.whl
  • Upload date:
  • Size: 78.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jenkinsapi-0.3.22-py3-none-any.whl
Algorithm Hash digest
SHA256 8804458b07aa40648c1ea62b2515acb9ee991e2773a7a7590d2db5e7eae644ba
MD5 5bc46c6604b88c0a5bc7a750aded26a5
BLAKE2b-256 20a3157eb7dd8c10ce485d53644a5b6d38de53015231861eb02e06782d1edb37

See more details on using hashes here.

Provenance

The following attestation bundles were made for jenkinsapi-0.3.22-py3-none-any.whl:

Publisher: release.yml on pycontribs/jenkinsapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page