Jenkins
This notebook, go over how to use Jenkins.
Overview
Jenkins integration are provide more power in CI/CD pipelines. Execute and control the pipline handling with AI.
Setup
First make sure that you have installed python-jenkins with the command below:
%pip install --upgrade --quiet python-jenkins
Credentials
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")
Instantiation
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"],
)
)
]
API Reference:JenkinsJobRun | JenkinsAPIWrapper
Invocation
You can now call invoke and pass arguments.
- 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"})
- Run the Jenkins Job
tools[0].invoke({"job": "job01", "parameters": {}, "action": "run"})
- Get job info
resp = tools[0].invoke({"job": "job01", "number": 1, "action": "status"})
if not resp["inProgress"]:
print(resp["result"])
- Delete the jenkins job
tools[0].invoke({"job": "job01", "action": "delete"})
Related
- Tool conceptual guide
- Tool how-to guides