Generate Jenkinsfile for CI/CD
✓Works with OpenClaudeYou 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
- Define the pipeline agent (
any,docker, orkubernetes) at the top level — this determines where stages execute - Add
environmentblock to set global variables likeDOCKER_REGISTRY,IMAGE_TAG, andGIT_COMMITfor reuse across stages - Create stages for Checkout (using
gitorcheckout scm), Build (compile and artifact creation), Test (unit and integration tests withjunitreport collection), and Deploy (push to registry or deployment target) - Use
postsections withalways,success, andfailureconditions to handle cleanup, notifications, and error handling - Add
optionsblock to set pipeline properties likebuildDiscarder(log rotation),timeout, andtimestampsfor readability - Integrate credentials using
credentials()binding in theenvironmentblock orwithCredentials()wrapper for sensitive data - Configure webhook or polling in the
triggersblock (githubPush(),pollSCM()) for automatic execution - Test locally with
declarative-linterplugin 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
Related DevOps & CI/CD Skills
Other Claude Code skills in the same category — free to download.
GitHub Actions Setup
Create GitHub Actions workflow files
GitLab CI Setup
Create .gitlab-ci.yml pipeline configuration
Deploy Script
Create deployment scripts for various platforms
Env Manager
Manage environment variables across environments
Infrastructure as Code
Generate Terraform/Pulumi configurations
Auto Release
Set up automated releases with semantic versioning
Rollback Script
Create rollback procedures and scripts
Blue-Green Deploy
Configure blue-green deployment strategy
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.