Skip to main content
Open In ColabOpen on GitHub

Jenkins

This notebook, go over how to use Jenkins.
First make sure that you have installed python-jenkins with the command below:

%pip install --upgrade --quiet  python-jenkins

Before start using Jenkins, first setup or get authorization to access Jenkins server.

import getpass
import os


def _set_env(var: str):
if not os.environ.get(var):
os.environ[var] = getpass.getpass(f"{var}: ")

_set_env("PASSWORD")

To disable the SSL Verify, set os.environ["PYTHONHTTPSVERIFY"] = "0"

from langchain_community.tools.jenkins.tool import JenkinsJobRun
from langchain_community.utilities.jenkins import JenkinsAPIWrapper


tools = [JenkinsJobRun(
api_wrapper=JenkinsAPIWrapper(
jenkins_server="https://example.com",
username="admin",
password=os.environ["PASSWORD"]
)
)]

You can now call invoke and pass arguments.

  1. Create the Jenkins job
jenkins_job_content = ""
src_file = "job1.xml"
with open(src_file) as fread:
jenkins_job_content = fread.read()
tools[0].invoke({'job': "job01", "config_xml": jenkins_job_content, "action": "create"})
  1. Run the Jenkins Job
tools[0].invoke({'job': "job01", "parameters": {}, "action": "run"})
  1. Get job info
resp = tools[0].invoke({'job': "job01", "number": 1,  "action": "status"})
if not resp["inProgress"]:
print(resp["result"])
  1. Delete the jenkins job
tools[0].invoke({'job': "job01", "action": "delete"})

Was this page helpful?