From 0c405245c460bba523ba6ecb4a7b871f32d13349 Mon Sep 17 00:00:00 2001 From: Amit Ghadge Date: Fri, 31 Jan 2025 09:50:10 -0800 Subject: [PATCH] [Integrations][Tool] Added Jenkins tools support (#29516) Thank you for contributing to LangChain! - [x] **PR title**: "package: description" - Where "package" is whichever of langchain, community, core, etc. is being modified. Use "docs: ..." for purely docs changes, "infra: ..." for CI changes. - Example: "community: add foobar LLM" - [x] **PR message**: ***Delete this entire checklist*** and replace with - **Description:** a description of the change - **Issue:** the issue # it fixes, if applicable - **Dependencies:** any dependencies required for this change - **Twitter handle:** if your PR gets announced, and you'd like a mention, we'll gladly shout you out! - [x] **Add tests and docs**: If you're adding a new integration, please include 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/docs/integrations` directory. - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/ Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. - If you are adding something to community, do not re-import it in langchain. If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17. --------- Co-authored-by: Chester Curme --- docs/docs/integrations/providers/jenkins.mdx | 17 ++ docs/docs/integrations/tools/jenkins.ipynb | 225 +++++++++++++++++++ libs/packages.yml | 4 + 3 files changed, 246 insertions(+) create mode 100644 docs/docs/integrations/providers/jenkins.mdx create mode 100644 docs/docs/integrations/tools/jenkins.ipynb diff --git a/docs/docs/integrations/providers/jenkins.mdx b/docs/docs/integrations/providers/jenkins.mdx new file mode 100644 index 00000000000..45e217d2422 --- /dev/null +++ b/docs/docs/integrations/providers/jenkins.mdx @@ -0,0 +1,17 @@ +# Jenkins + +[Jenkins](https://www.jenkins.io/) is an open-source automation platform that enables +software teams to streamline their development workflows. It's widely adopted in the +DevOps community as a tool for automating the building, testing, and deployment of +applications through CI/CD pipelines. + + +## Installation and Setup + +```bash +pip install langchain-jenkins +``` + +## Tools + +See detail on available tools [here](/docs/integrations/tools/jenkins). diff --git a/docs/docs/integrations/tools/jenkins.ipynb b/docs/docs/integrations/tools/jenkins.ipynb new file mode 100644 index 00000000000..c8fdd05b40f --- /dev/null +++ b/docs/docs/integrations/tools/jenkins.ipynb @@ -0,0 +1,225 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Jenkins\n", + "\n", + "Tools for interacting with [Jenkins](https://www.jenkins.io/).\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Overview\n", + "\n", + "The `langchain-jenkins` package allows you to execute and control CI/CD pipelines with\n", + "Jenkins." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setup\n", + "\n", + "Install `langchain-jenkins`:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [ + "%pip install --upgrade --quiet langchain-jenkins" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Credentials\n", + "\n", + "You'll need to setup or obtain authorization to access Jenkins server." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [ + "import getpass\n", + "import os\n", + "\n", + "\n", + "def _set_env(var: str):\n", + " if not os.environ.get(var):\n", + " os.environ[var] = getpass.getpass(f\"{var}: \")\n", + "\n", + "\n", + "_set_env(\"PASSWORD\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Instantiation\n", + "To disable the SSL Verify, set `os.environ[\"PYTHONHTTPSVERIFY\"] = \"0\"`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_jenkins import JenkinsAPIWrapper, JenkinsJobRun\n", + "\n", + "tools = [\n", + " JenkinsJobRun(\n", + " api_wrapper=JenkinsAPIWrapper(\n", + " jenkins_server=\"https://example.com\",\n", + " username=\"admin\",\n", + " password=os.environ[\"PASSWORD\"],\n", + " )\n", + " )\n", + "]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Invocation\n", + "You can now call invoke and pass arguments." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Create the Jenkins job" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "jenkins_job_content = \"\"\n", + "src_file = \"job1.xml\"\n", + "with open(src_file) as fread:\n", + " jenkins_job_content = fread.read()\n", + "tools[0].invoke({\"job\": \"job01\", \"config_xml\": jenkins_job_content, \"action\": \"create\"})" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Run the Jenkins Job" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tools[0].invoke({\"job\": \"job01\", \"parameters\": {}, \"action\": \"run\"})" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Get job info" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "resp = tools[0].invoke({\"job\": \"job01\", \"number\": 1, \"action\": \"status\"})\n", + "if not resp[\"inProgress\"]:\n", + " print(resp[\"result\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Delete the jenkins job" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tools[0].invoke({\"job\": \"job01\", \"action\": \"delete\"})" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Chaining\n", + "\n", + "TODO.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## API reference\n", + "\n", + "For detailed documentation [API reference](https://python.langchain.com/docs/integrations/tools/jenkins/)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.1" + }, + "vscode": { + "interpreter": { + "hash": "3929050b09828356c9f5ebaf862d05c053d8228eddbc70f990c168e54dd824ba" + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/libs/packages.yml b/libs/packages.yml index 1582c8a196f..0665b3b10f0 100644 --- a/libs/packages.yml +++ b/libs/packages.yml @@ -371,3 +371,7 @@ packages: downloads: 0 js: '@langchain/deepseek' provider_page: deepseek +- name: langchain-jenkins + path: . + repo: Amitgb14/langchain_jenkins + downloads: 0