Operations 3 min read

Using Python‑Jenkins API to Manage Jenkins Jobs and Views

This guide explains how to install the python‑jenkins library, connect to a Jenkins server from Python, and perform common job and view operations such as building jobs with or without parameters, enabling/disabling jobs, copying jobs, and managing views.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Using Python‑Jenkins API to Manage Jenkins Jobs and Views

Background: the need to trigger Jenkins builds from backend code leads to using the python‑jenkins library, which provides a Python wrapper for Jenkins API operations.

Installation: sudo pip install python-jenkins.

Connecting to Jenkins: import the jenkins module and create a jenkins.Jenkins instance with the server URL, username, and password.

Job operations: server.build_job(job_name) builds a job without parameters;

server.build_job(job_name, {"param1":"value1", "param2":"value2"})

builds a job with parameters.

Additional job actions: server.get_job_info(job_name) retrieves job configuration and build information; server.enable_job(job_name) and server.disable_job(job_name) enable or pause a job; server.copy_job('job', 'job_copy') creates a copy of an existing job.

View operations: server.get_view_config(view_name) obtains view configuration; server.create_view('view4', jenkins.EMPTY_VIEW_CONFIG_XML) creates a new view; server.delete_view(view_name) removes a view; server.view_exists(view_name) checks for view existence.

Other useful functions include retrieving the last build number via server.get_job_info(job)['lastBuild'] and checking if a build is in progress with server.get_build_info(job, build_number)['building'].

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

python-jenkins
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.