/devops-skills:jenkinsfile-generatorfrom devops-skills
Generates production-ready Jenkinsfiles for Declarative and Scripted pipeline syntaxes. Includes templates, best practices, and validation for CI/CD pipelines.
Ships in devops-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Generate production-ready Jenkinsfiles following best practices. All generated files are validated using devops-skills:jenkinsfile-validator skill.
// Minimal Declarative Pipeline
pipeline {
agent any
stages {
stage('Build') { steps { sh 'make' } }
stage('Test') { steps { sh 'make test' } }
}
}
// Error-tolerant stage
stage('Flaky Tests') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
sh 'run-flaky-tests.sh'
}
}
}
// Conditional deployment with approval
stage('Deploy') {
when { branch 'main'; beforeAgent true }
input { message 'Deploy to production?' }
steps { sh './deploy.sh' }
}
| Option | Purpose |
|---|---|
timeout(time: 1, unit: 'HOURS') | Prevent hung builds |
buildDiscarder(logRotator(numToKeepStr: '10')) | Manage disk space |
disableConcurrentBuilds() | Prevent race conditions |
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') | Continue on error |
Process:
assets/templates/declarative/basic.Jenkinsfile to understand the standard structurereferences/best_practices.md for performance, security, and reliability patternsreferences/common_plugins.md for plugin-specific syntaxfailFast true or parallelsAlwaysFailFast() for parallel blocksfingerprint: true when using archiveArtifactsWhen: Complex conditional logic, dynamic generation, full Groovy control Process:
assets/templates/scripted/basic.Jenkinsfile for node/stage patternsUse parallel {} block or matrix {} with axes {} for multi-dimensional builds.
Add SonarQube, OWASP Dependency-Check, Trivy stages with fail thresholds.
python3 scripts/generate_shared_library.py --name my-library --package org.example
agent any // Any available agent
agent { label 'linux && docker' } // Label-based
agent { docker { image 'maven:3.9.11-eclipse-temurin-21' } }
agent { kubernetes { yaml '...' } } // K8s pod template
agent { kubernetes { yamlFile 'pod.yaml' } } // External YAML
environment {
VERSION = '1.0.0'
AWS_KEY = credentials('aws-key-id') // Creates _USR and _PSW vars
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
timestamps()
parallelsAlwaysFailFast()
durabilityHint('PERFORMANCE_OPTIMIZED') // 2-6x faster for simple pipelines
}
parameters {
string(name: 'VERSION', defaultValue: '1.0.0')
choice(name: 'ENV', choices: ['dev', 'staging', 'prod'])
booleanParam(name: 'SKIP_TESTS', defaultValue: false)
}
| Condition | Example |
|---|---|
branch | branch 'main' or branch pattern: 'release/*', comparator: 'GLOB' |
tag | tag pattern: 'v*', comparator: 'GLOB' |
changeRequest | changeRequest target: 'main' |
changeset | changeset 'src/**/*.java' |
expression | expression { env.DEPLOY == 'true' } |
allOf/anyOf/not | Combine conditions |
Add beforeAgent true to skip agent allocation if condition fails.
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { sh '...' }
warnError('msg') { sh '...' } // Mark UNSTABLE but continue
unstable(message: 'Coverage low') // Explicit UNSTABLE
error('Config missing') // Fail without stack trace
post {
always { junit '**/target/*.xml'; cleanWs() }
success { archiveArtifacts artifacts: '**/*.jar', fingerprint: true }
failure { slackSend color: 'danger', message: 'Build failed' }
fixed { echo 'Build fixed!' }
}
Order: always → changed → fixed → regression → failure → success → unstable → cleanup
NOTE: Always use fingerprint: true with archiveArtifacts for build traceability and artifact tracking.
IMPORTANT: Always ensure parallel blocks fail fast on first failure using one of these approaches:
Option 1: Global (RECOMMENDED) - Use parallelsAlwaysFailFast() in pipeline options:
options {
parallelsAlwaysFailFast() // Applies to ALL parallel blocks in pipeline
}
This is the preferred approach as it covers all parallel blocks automatically.
Option 2: Per-block - Use failFast true on individual parallel stages:
stage('Tests') {
failFast true // Only affects this parallel block
parallel {
stage('Unit') { steps { sh 'npm test:unit' } }
stage('E2E') { steps { sh 'npm test:e2e' } }
}
}
NOTE: When parallelsAlwaysFailFast() is set in options, explicit failFast true on individual parallel blocks is redundant.
stage('Matrix') {
failFast true
matrix {
axes {
axis { name 'PLATFORM'; values 'linux', 'windows' }
axis { name 'BROWSER'; values 'chrome', 'firefox' }
}
excludes { exclude { axis { name 'PLATFORM'; values 'linux' }; axis { name 'BROWSER'; values 'safari' } } }
stages { stage('Test') { steps { echo "Testing ${PLATFORM}/${BROWSER}" } } }
}
}
### Input (Manual Approval)
```groovy
stage('Deploy') {
input { message 'Deploy?'; ok 'Deploy'; submitter 'admin,ops' }
steps { sh './deploy.sh' }
}
IMPORTANT: Place input outside steps to avoid holding agents.
node('agent-label') {
try {
stage('Build') { sh 'make build' }
stage('Test') { sh 'make test' }
} catch (Exception e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
deleteDir()
}
}
// Parallel
parallel(
'Unit': { node { sh 'npm test:unit' } },
'E2E': { node { sh 'npm test:e2e' } }
)
// Environment
withEnv(['VERSION=1.0.0']) { sh 'echo $VERSION' }
withCredentials([string(credentialsId: 'key', variable: 'KEY')]) { sh 'curl -H "Auth: $KEY" ...' }
@NonCPS
def parseJson(String json) {
new groovy.json.JsonSlurper().parseText(json)
}
Rules: No pipeline steps (sh, echo) inside @NonCPS. Use for JsonSlurper, iterators, regex Matchers.
agent { docker { image 'maven:3.9.11'; args '-v $HOME/.m2:/root/.m2'; reuseNode true } }
def img = docker.build("myapp:${BUILD_NUMBER}")
docker.withRegistry('https://registry.example.com', 'creds') { img.push(); img.push('latest') }
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.9.11-eclipse-temurin-21
command: [sleep, 99d]
'''
}
}
// Use: container('maven') { sh 'mvn package' }
@Library('my-shared-library') _
// or dynamically: library '[email protected]'
// vars/log.groovy
def info(msg) { echo "INFO: ${msg}" }
// Usage
log.info 'Starting build'
CRITICAL: ALWAYS validate using devops-skills:jenkinsfile-validator skill:
devops-skills:jenkinsfile-validator skillfailFast true for parallel blocks → apply by defaultValidation commands:
# Full validation (syntax + security + best practices)
bash scripts/validate_jenkinsfile.sh Jenkinsfile
# Syntax only (fastest)
bash scripts/validate_jenkinsfile.sh --syntax-only Jenkinsfile
When to use scripts vs manual generation:
# Declarative (simple pipelines)
python3 scripts/generate_declarative.py --output Jenkinsfile --stages build,test,deploy --agent docker
# Scripted (simple pipelines)
python3 scripts/generate_scripted.py --output Jenkinsfile --stages build,test --agent label:linux
# Shared Library (always use script for scaffolding)
python3 scripts/generate_shared_library.py --name my-library --package com.example
Always consult Context7 or WebSearch for:
references/common_plugins.mdMay skip external lookup when:
references/common_plugins.mdsh, checkout scm, junit)Plugins covered in common_plugins.md: Git, Docker, Kubernetes, Credentials, JUnit, Slack, SonarQube, OWASP Dependency-Check, Email, AWS, Azure, HTTP Request, Microsoft Teams, Nexus, Artifactory, GitHub
Lookup methods (in order of preference):
mcp__context7__resolve-library-id with /jenkinsci/<plugin-name>-pluginJenkins [plugin-name] plugin documentation 2025references/best_practices.md - Performance, security, reliability patternsreferences/common_plugins.md - Git, Docker, K8s, credentials, notificationsassets/templates/ - Declarative and scripted templatesdevops-skills:jenkinsfile-validator skill - Syntax and best practices validationAlways prefer Declarative unless scripted flexibility is required.
assets/templates/declarative/basic.Jenkinsfile (opens in a new tab)assets/templates/scripted/basic.Jenkinsfile (opens in a new tab)examples/declarative-ci-basic.Jenkinsfile (opens in a new tab)examples/declarative-docker.Jenkinsfile (opens in a new tab)examples/declarative-kubernetes.Jenkinsfile (opens in a new tab)examples/declarative-matrix.Jenkinsfile (opens in a new tab)examples/declarative-parallel.Jenkinsfile (opens in a new tab)examples/declarative-security-scan.Jenkinsfile (opens in a new tab)examples/declarative-shared-library.Jenkinsfile (opens in a new tab)examples/scripted-basic.Jenkinsfile (opens in a new tab)examples/scripted-conditional.Jenkinsfile (opens in a new tab)examples/scripted-docker.Jenkinsfile (opens in a new tab)references/best_practices.md (opens in a new tab)references/common_plugins.md (opens in a new tab)scripts/generate_declarative.py (opens in a new tab)scripts/generate_scripted.py (opens in a new tab)scripts/generate_shared_library.py (opens in a new tab)scripts/lib/__init__.py (opens in a new tab)scripts/lib/common_patterns.py (opens in a new tab)scripts/lib/syntax_helpers.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (gitjfmd/ansible-skills) — no native marketplace selected
npx claudepluginhub p/gitjfmd-devops-skills-devops-skills-plugin31 skills in this plugin
/ansible-generatorComprehensive toolkit for generating best practice Ansible playbooks, roles, tasks, and inventory files./ansible-validatorComprehensive toolkit for validating, linting, testing, and automating Ansible playbooks, roles, and collections. Use this skill when working with Ansible files (.yml, .yaml playbooks, roles, inventories), validating automation code, debugging playbook execution, performing dry-run testing with check mode, or working with custom modules and collections./azure-pipelines-generatorComprehensive toolkit for generating best practice Azure DevOps Pipelines following current standards and conventions. Use this skill when creating new Azure Pipelines, implementing CI/CD workflows, or building deployment pipelines.Other plugins' skills for the same job