{"id":72998,"date":"2025-09-17T11:27:40","date_gmt":"2025-09-17T05:57:40","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=72998"},"modified":"2025-09-17T11:55:27","modified_gmt":"2025-09-17T06:25:27","slug":"how-to-create-ci-cd-pipeline-for-genai-application-using-jenkins","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-create-ci-cd-pipeline-for-genai-application-using-jenkins\/","title":{"rendered":"How to Create CI\/CD Pipeline for GenAI Application using Jenkins"},"content":{"rendered":"<p><span style=\"font-size: 1.28571rem;\">Introduction<\/span><\/p>\n<p>Generative AI (GenAI) applications are becoming increasingly popular in enterprises, powering use cases like chatbots, text summarization, code generation, and more. However, developing these applications is only half the battle \u2014 ensuring smooth deployment, scalability, and continuous improvement is where CI\/CD (Continuous Integration\/Continuous Deployment) pipelines play a critical role.<\/p>\n<p>In this blog, we\u2019ll walk you through how to set up a Jenkins-based CI\/CD pipeline for a GenAI application, covering code integration, testing, containerization, and automated deployment.<\/p>\n<h3>Why CI\/CD for GenAI Applications?<\/h3>\n<h4>GenAI apps often involve:<\/h4>\n<ul>\n<li>Frequent model updates (fine-tuning or prompt engineering).<\/li>\n<li>Integration with APIs like OpenAI, Anthropic, or HuggingFace.<\/li>\n<li>Deployment across multiple environments (dev, staging, prod).<\/li>\n<\/ul>\n<h4>CI\/CD helps by:<\/h4>\n<ul>\n<li>Automating builds, testing, and deployments.<\/li>\n<li>Reducing human error.<\/li>\n<li>Enabling faster iterations.<\/li>\n<li>Architecture of the CI\/CD Pipeline<\/li>\n<\/ul>\n<p><strong>Our pipeline will look like this:<\/strong><\/p>\n<ul>\n<li><strong>Source Code:<\/strong> Code hosted on GitHub\/GitLab.<\/li>\n<li><strong>Build Stage:<\/strong> Python\/Node environment setup, dependency installation.<\/li>\n<li><strong>Test Stage:<\/strong> Unit tests for API endpoints, model response checks.<\/li>\n<li><strong>Containerization:<\/strong> Dockerize the GenAI application.<\/li>\n<li><strong>Deployment:<\/strong> Push to AWS\/GCP\/Azure or Kubernetes.<\/li>\n<\/ul>\n<h3>Step 1: Prerequisites<\/h3>\n<p>Before starting, ensure you have:<\/p>\n<ul>\n<li>Jenkins installed (on VM, Docker, or Kubernetes).<\/li>\n<li>GitHub repository with GenAI application code.<\/li>\n<li>Docker installed on Jenkins server.<\/li>\n<li>Cloud environment or server to deploy the app.<\/li>\n<\/ul>\n<h3>Step 2: Example GenAI Application (FastAPI + OpenAI)<\/h3>\n<p>Here\u2019s a minimal FastAPI app using OpenAI API:<\/p>\n<pre><code class=\"language-python\">\r\n# app\/main.py\r\nfrom fastapi import FastAPI\r\nimport openai\r\nimport os\r\n\r\napp = FastAPI()\r\n\r\nopenai.api_key = os.getenv(\"OPENAI_API_KEY\")\r\n\r\n@app.get(\"\/generate\")\r\ndef generate(prompt: str):\r\n    response = openai.Completion.create(\r\n        engine=\"text-davinci-003\",\r\n        prompt=prompt,\r\n        max_tokens=100\r\n    )\r\n    return {\"output\": response[\"choices\"][0][\"text\"]}\r\n<\/code><\/pre>\n<h2>Step 3: Dockerfile:<\/h2>\n<p>We\u2019ll containerise the application so Jenkins can deploy it anywhere.<\/p>\n<pre><code>\r\n# Dockerfile\r\nFROM python:3.10-slim\r\n\r\nWORKDIR \/app\r\nCOPY requirements.txt .\r\nRUN pip install -r requirements.txt\r\n\r\nCOPY . .\r\nCMD [\"uvicorn\", \"app.main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"8000\"]\r\n\r\n\u00a0\r\n<\/code><\/pre>\n<h2>Step 4: Jenkins Pipeline Script (Jenkinsfile)<\/h2>\n<p>This Jenkinsfile automates build \u2192 test \u2192 docker build \u2192 deploy.<\/p>\n<pre><code class=\"language-groovy\">\r\npipeline {\r\n    agent any\r\n\r\n    environment {\r\n        DOCKER_IMAGE = \"genai-app:latest\"\r\n        REGISTRY = \"your-dockerhub-username\/genai-app\"\r\n    }\r\n\r\n    stages {\r\n        stage('Checkout') {\r\n            steps {\r\n                git branch: 'main', url: 'https:\/\/github.com\/your-repo\/genai-app.git'\r\n            }\r\n        }\r\n\r\n        stage('Build') {\r\n            steps {\r\n                sh 'pip install -r requirements.txt'\r\n            }\r\n        }\r\n\r\n        stage('Test') {\r\n            steps {\r\n                sh 'pytest tests\/' \/\/ Ensure you have test cases for API\r\n            }\r\n        }\r\n\r\n        stage('Docker Build') {\r\n            steps {\r\n                sh 'docker build -t $DOCKER_IMAGE .'\r\n            }\r\n        }\r\n\r\n        stage('Push to Registry') {\r\n            steps {\r\n                withCredentials([usernamePassword(credentialsId: 'dockerhub-cred', usernameVariable: 'USER', passwordVariable: 'PASS')]) {\r\n                    sh 'echo $PASS | docker login -u $USER --password-stdin'\r\n                    sh 'docker tag $DOCKER_IMAGE $REGISTRY:latest'\r\n                    sh 'docker push $REGISTRY:latest'\r\n                }\r\n            }\r\n        }\r\n\r\n        stage('Deploy') {\r\n            steps {\r\n                sshagent(['server-ssh-cred']) {\r\n                    sh 'ssh user@your-server \"docker pull $REGISTRY:latest &amp;&amp; docker run -d -p 8000:8000 $REGISTRY:latest\"'\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n<h2>Step 5: Testing Your Pipeline<\/h2>\n<ul>\n<li>Commit and push code to GitHub.<\/li>\n<li>Jenkins auto-triggers pipeline.<\/li>\n<li>Watch stages (checkout \u2192 test \u2192 dockerize \u2192 deploy).<\/li>\n<li>Access your app at <strong>http:\/\/your-server-ip:8000\/generate?prompt=Hello<\/strong><\/li>\n<\/ul>\n<h2>Best Practices for GenAI CI\/CD<\/h2>\n<ul>\n<li>Use secrets management (Jenkins credentials store, Vault, AWS Secrets Manager) for API keys.<\/li>\n<li>Run integration tests on AI responses (e.g., non-empty, within latency).<\/li>\n<li>Implement rolling updates or blue-green deployments for production.<\/li>\n<li>Add monitoring &amp; logging (Prometheus, ELK, OpenTelemetry) for tracking model performance.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Building a GenAI application is exciting, but without proper automation, deployments can become error-prone and time-consuming. Using Jenkins CI\/CD, you can streamline your workflow \u2014 from code changes to containerized deployments \u2014 ensuring your GenAI app is always production-ready.<\/p>\n<p>With the setup we discussed, you now have a fully automated pipeline that can:<\/p>\n<p>Pull the latest code.<br \/>\nRun tests.<br \/>\nBuild Docker images.<br \/>\nDeploy to servers\/cloud.<br \/>\nThis approach not only saves time but also ensures faster iterations, higher reliability, and smoother scaling for your Generative AI applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Generative AI (GenAI) applications are becoming increasingly popular in enterprises, powering use cases like chatbots, text summarization, code generation, and more. However, developing these applications is only half the battle \u2014 ensuring smooth deployment, scalability, and continuous improvement is where CI\/CD (Continuous Integration\/Continuous Deployment) pipelines play a critical role. In this blog, we\u2019ll walk [&hellip;]<\/p>\n","protected":false},"author":1509,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":172},"categories":[5871],"tags":[5309,2844,1682],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/72998"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1509"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=72998"}],"version-history":[{"count":9,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/72998\/revisions"}],"predecessor-version":[{"id":76517,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/72998\/revisions\/76517"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=72998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=72998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=72998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}