Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
DevOps & CI/CDintermediate

Jenkins Pipeline

Share

Generate Jenkinsfile for CI/CD

Works with OpenClaude

You are a DevOps engineer specializing in Jenkins automation. The user wants to generate a production-ready Jenkinsfile that defines a complete CI/CD pipeline with stages for building, testing, and deploying applications.

What to check first

  • Verify Jenkins is installed and the Pipeline plugin is enabled: curl -s http://localhost:8080/pluginManager/api/json | grep -i pipeline
  • Confirm your Git repository supports webhooks for automatic pipeline triggers
  • Check that required credentials (Docker registry, deployment keys) are stored in Jenkins Credentials Manager

Steps

  1. Define the pipeline agent (any, docker, or kubernetes) at the top level — this determines where stages execute
  2. Add environment block to set global variables like DOCKER_REGISTRY, IMAGE_TAG, and GIT_COMMIT for reuse across stages
  3. Create stages for Checkout (using git or checkout scm), Build (compile and artifact creation), Test (unit and integration tests with junit report collection), and Deploy (push to registry or deployment target)
  4. Use post sections with always, success, and failure conditions to handle cleanup, notifications, and error handling
  5. Add options block to set pipeline properties like buildDiscarder (log rotation), timeout, and timestamps for readability
  6. Integrate credentials using credentials() binding in the environment block or withCredentials() wrapper for sensitive data
  7. Configure webhook or polling in the triggers block (githubPush(), pollSCM()) for automatic execution
  8. Test locally with declarative-linter plugin or validate syntax via Jenkins UI before committing

Code

pipeline {
    agent any
    
    options {
        buildDiscarder(logRotator(numToKeepStr: '10'))
        timeout(time: 30, unit: 'MINUTES')
        timestamps()
    }
    
    environment {
        DOCKER_REGISTRY = 'docker.io'
        IMAGE_NAME = "${DOCKER_REGISTRY}/myapp"
        IMAGE_TAG = "${BUILD_NUMBER}-${GIT_COMMIT.take(7)}"
        REGISTRY_CREDENTIALS = credentials('docker-registry-creds')
    }
    
    triggers {
        githubPush()
        pollSCM('H/15 * * * *')
    }
    
    stages {
        stage('Checkout') {
            steps {
                checkout scm
                script {
                    env.GIT_COMMIT_MSG = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim()
                }
            }
        }
        
        stage('Build') {
            steps {
                script {
                    sh '''
                        echo "Building application..."
                        ./gradlew clean build -x test
                    '''
                }
            }
        }
        
        stage('Test') {

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
devopsjenkinspipeline

Install command:

curl -o ~/.claude/skills/jenkins-pipeline.md https://claude-skills-hub.vercel.app/skills/devops/jenkins-pipeline.md

Related DevOps & CI/CD Skills

Other Claude Code skills in the same category — free to download.

Want a DevOps & CI/CD skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.