Loading...
Loading...
Generate/create/scaffold Jenkinsfile — declarative, scripted, shared library, CI/CD pipelines.
npx skill4agent add akin-ozer/cc-devops-skills jenkinsfile-generatorvars/src/resources/| Template | Path | Use When |
|---|---|---|
| Declarative basic | | Standard CI/CD with predictable stages |
| Declarative parallel example | | Parallel test/build branches with fail-fast behavior |
| Declarative kubernetes example | | Kubernetes agent execution using pod templates |
| Scripted basic | | Complex conditional logic or generated stages |
| Shared library scaffold | Generated by | Reusable pipeline functions and organization-wide patterns |
// 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 |
|---|---|
| Prevent hung builds |
| Manage disk space |
| Prevent race conditions |
| Continue on error |
assets/templates/declarative/basic.Jenkinsfilereferences/best_practices.mdreferences/common_plugins.mdfailFast trueparallelsAlwaysFailFast()fingerprint: truearchiveArtifactsassets/templates/scripted/basic.Jenkinsfileparallel {}matrix {}axes {}parallelsAlwaysFailFast()failFast truepython3 scripts/generate_shared_library.py --name my-library --package org.exampleagent 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 YAMLenvironment {
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 |
|---|---|
| |
| |
| |
| |
| |
| Combine conditions |
beforeAgent truecatchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { sh '...' }
warnError('msg') { sh '...' } // Mark UNSTABLE but continue
unstable(message: 'Coverage low') // Explicit UNSTABLE
error('Config missing') // Fail without stack tracepost {
always { junit '**/target/*.xml'; cleanWs() }
success { archiveArtifacts artifacts: '**/*.jar', fingerprint: true }
failure { slackSend color: 'danger', message: 'Build failed' }
fixed { echo 'Build fixed!' }
}fingerprint: truearchiveArtifactsparallelsAlwaysFailFast()options {
parallelsAlwaysFailFast() // Applies to ALL parallel blocks in pipeline
}failFast truestage('Tests') {
failFast true // Only affects this parallel block
parallel {
stage('Unit') { steps { sh 'npm test:unit' } }
stage('E2E') { steps { sh 'npm test:e2e' } }
}
}parallelsAlwaysFailFast()failFast truestage('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}" } } }
}
}stage('Deploy') {
input { message 'Deploy?'; ok 'Deploy'; submitter 'admin,ops' }
steps { sh './deploy.sh' }
}inputnode('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)
}shechoagent { 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 'my-library@1.0.0'
// vars/log.groovy
def info(msg) { echo "INFO: ${msg}" }
// Usage
log.info 'Starting build'devops-skills:jenkinsfile-validatorfailFast true# Full validation (syntax + security + best practices)
bash ../jenkinsfile-validator/scripts/validate_jenkinsfile.sh Jenkinsfile
# Syntax only (fastest)
bash ../jenkinsfile-validator/scripts/validate_jenkinsfile.sh --syntax-only Jenkinsfilegenerate_declarative.py--output--stages--agent--build-tool--build-cmd--test-cmd--deploy-*--notification-*--archive-artifacts--k8s-yaml--k8s-yaml.yaml.yml[a-z0-9_-]generate_scripted.py--outputgenerate_shared_library.py--name--package--outputdeployment/<name># 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--k8s-yamlreferences/common_plugins.mdreferences/common_plugins.mdshcheckout scmjunitmcp__context7__resolve-library-id/jenkinsci/<plugin-name>-pluginJenkins [plugin-name] plugin documentation 2025references/best_practices.mdreferences/common_plugins.mdassets/templates/devops-skills:jenkinsfile-validator