Overview
Jenkins pipelines define CI/CD workflows as code using Groovy-based DSL. Supports Declarative (structured) and Scripted (flexible) syntax with shared libraries for reuse across projects.
Capabilities
- Declarative and Scripted pipeline authoring
- Parallel stage execution for faster builds
- Shared library development and versioning
- Credential management with Credentials plugin
- Agent/label-based build node selection
- Blue Ocean visual pipeline editor integration
When to Use
Trigger phrases:
"jenkins pipelines"
"Jenkins pipeline as code — Declarative/Scripted pipelines, shared libraries, age"
CI/CD for Java, Node.js, Python, or polyglot projects
Complex multi-stage build/test/deploy workflows
Teams already running Jenkins infrastructure
Need shared pipeline logic across many repositories
Enterprise environments with Jenkins + LDAP/RBAC
When NOT to Use
- Task is outside your authorization scope
- You need to implement controls (use implementing-* skills)
- Task is about analysis, not action (use analyzing-* skills)
- You don't have access to target systems
- Task requires compliance expertise (consult professionals)
- Task is about defense, not offense (use defensive skills)
Pseudo Code
The jenkins-pipelines workflow follows a standard pipeline pattern.
Core flow:
# jenkins-pipelines primary flow
input = prepare(raw_data)
result = process(input, config={agents, code, credentials, declarative, jenkins})
validate(result)
deliver(result)
Error handling:
on error:
log(error_details)
retry_with_backoff(max=3)
if still_failing: alert_and_escalate()
Declarative Pipeline
// Jenkinsfile
pipeline {
agent { label 'linux' }
environment {
APP_NAME = 'my-app'
REGISTRY = 'ghcr.io'
}
stages {
stage('Build') {
steps {
sh 'npm ci'
sh 'npm run build'
}
}
stage('Test') {
parallel {
stage('Unit Tests') { steps { sh 'npm test' } }
stage('Lint') { steps { sh 'npm run lint' } }
}
}
stage('Deploy') {
when { branch 'main' }
steps {
sh 'docker build -t $REGISTRY/$APP_NAME:$BUILD_NUMBER .'
sh 'docker push $REGISTRY/$APP_NAME:$BUILD_NUMBER'
}
}
}
post {
always { cleanWs() }
failure { slackSend channel: '#builds', message: "FAILED: ${env.JOB_NAME}" }
}
}
Shared Library
// vars/deployK8s.groovy
def call(Map config) {
sh "kubectl set image deployment/${config.app} ${config.container}=${config.image}"
sh "kubectl rollout status deployment/${config.app}"
}
// Jenkinsfile usage
@Library('my-shared-lib@main') _
deployK8s(app: 'api', container: 'api', image: 'ghcr.io/api:v1')
Credentials Usage
stage('Deploy') {
steps {
withCredentials([string(credentialsId: 'api-key', variable: 'TOKEN')]) {
sh 'curl -H "Authorization: Bearer $TOKEN" https://api.example.com/deploy'
}
withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {
sh 'kubectl --kubeconfig=$KUBECONFIG apply -f deploy.yaml'
}
}
}
Common Patterns
- Multibranch pipeline: auto-discovers branches with Jenkinsfile
- Shared libraries: reusable pipeline logic in
vars/, src/, resources/
- Parameters:
parameters { string(name: 'VERSION', defaultValue: 'latest') }
- Input gates:
input message: 'Deploy to production?'
- Matrix builds:
matrix { axes { axis { name 'OS'; values 'linux', 'darwin' } } }
How to Use
- Define infrastructure as code (Terraform, CloudFormation, Pulumi)
- Review changes through PR process before applying
- Configure monitoring and alerting for critical paths
- Set up secrets management (Vault, AWS Secrets Manager, etc.)
- Document runbooks for deployment, rollback, and incident response
- Test disaster recovery procedures regularly
Red Flags
- Infrastructure changes without review: Unreviewed changes cause outages — use PRs for infra code
- No rollback strategy: Every deployment needs a tested rollback plan before it runs
- Secrets in configuration files: Secrets in YAML/JSON get committed to version control
- Missing monitoring and alerting: Without monitoring, outages go undetected until users report them
- No documentation for runbooks: Without runbooks, on-call engineers waste time re-discovering procedures
Verification
Process
- Analyze the task requirements
- Apply domain expertise
- Verify output quality
Anti-Rationalization Table
| Rationalization |
Reality |
| "Manual deployments are fine" |
Manual deployments are error-prone and不可 repeatable. Automate. |
| "We do not need monitoring" |
Without monitoring, you are flying blind. Add observability from day one. |
| "Infrastructure as code is overkill" |
IaC enables reproducibility, version control, and disaster recovery. |
1---2name: jenkins-pipelines3description: Use when jenkins pipeline as code — Declarative/Scripted pipelines, shared libraries, agents, stages, credentials. Use when working with jenkins pipelines.4license: Apache-2.05---6789## Overview1011Jenkins pipelines define CI/CD workflows as code using Groovy-based DSL. Supports Declarative (structured) and Scripted (flexible) syntax with shared libraries for reuse across projects.1213## Capabilities1415- Declarative and Scripted pipeline authoring16- Parallel stage execution for faster builds17- Shared library development and versioning18- Credential management with Credentials plugin19- Agent/label-based build node selection20- Blue Ocean visual pipeline editor integration2122## When to Use23**Trigger phrases:**24- "jenkins pipelines"25- "Jenkins pipeline as code — Declarative/Scripted pipelines, shared libraries, age"262728- CI/CD for Java, Node.js, Python, or polyglot projects29- Complex multi-stage build/test/deploy workflows30- Teams already running Jenkins infrastructure31- Need shared pipeline logic across many repositories32- Enterprise environments with Jenkins + LDAP/RBAC3334## When NOT to Use3536- Task is outside your authorization scope37- You need to implement controls (use implementing-* skills)38- Task is about analysis, not action (use analyzing-* skills)39- You don't have access to target systems40- Task requires compliance expertise (consult professionals)41- Task is about defense, not offense (use defensive skills)424344## Pseudo Code4546The jenkins-pipelines workflow follows a standard pipeline pattern.4748Core flow:49```50# jenkins-pipelines primary flow51input = prepare(raw_data)52result = process(input, config={agents, code, credentials, declarative, jenkins})53validate(result)54deliver(result)55```5657Error handling:58```59on error:60 log(error_details)61 retry_with_backoff(max=3)62 if still_failing: alert_and_escalate()63```646566### Declarative Pipeline67```groovy68// Jenkinsfile69pipeline {70 agent { label 'linux' }71 environment {72 APP_NAME = 'my-app'73 REGISTRY = 'ghcr.io'74 }75 stages {76 stage('Build') {77 steps {78 sh 'npm ci'79 sh 'npm run build'80 }81 }82 stage('Test') {83 parallel {84 stage('Unit Tests') { steps { sh 'npm test' } }85 stage('Lint') { steps { sh 'npm run lint' } }86 }87 }88 stage('Deploy') {89 when { branch 'main' }90 steps {91 sh 'docker build -t $REGISTRY/$APP_NAME:$BUILD_NUMBER .'92 sh 'docker push $REGISTRY/$APP_NAME:$BUILD_NUMBER'93 }94 }95 }96 post {97 always { cleanWs() }98 failure { slackSend channel: '#builds', message: "FAILED: ${env.JOB_NAME}" }99 }100}101```102103### Shared Library104```groovy105// vars/deployK8s.groovy106def call(Map config) {107 sh "kubectl set image deployment/${config.app} ${config.container}=${config.image}"108 sh "kubectl rollout status deployment/${config.app}"109}110111// Jenkinsfile usage112@Library('my-shared-lib@main') _113deployK8s(app: 'api', container: 'api', image: 'ghcr.io/api:v1')114```115116### Credentials Usage117```groovy118stage('Deploy') {119 steps {120 withCredentials([string(credentialsId: 'api-key', variable: 'TOKEN')]) {121 sh 'curl -H "Authorization: Bearer $TOKEN" https://api.example.com/deploy'122 }123 withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {124 sh 'kubectl --kubeconfig=$KUBECONFIG apply -f deploy.yaml'125 }126 }127}128```129130## Common Patterns131132- **Multibranch pipeline**: auto-discovers branches with Jenkinsfile133- **Shared libraries**: reusable pipeline logic in `vars/`, `src/`, `resources/`134- **Parameters**: `parameters { string(name: 'VERSION', defaultValue: 'latest') }`135- **Input gates**: `input message: 'Deploy to production?'`136- **Matrix builds**: `matrix { axes { axis { name 'OS'; values 'linux', 'darwin' } } }`137138## How to Use1391401. Define infrastructure as code (Terraform, CloudFormation, Pulumi)1412. Review changes through PR process before applying1423. Configure monitoring and alerting for critical paths1434. Set up secrets management (Vault, AWS Secrets Manager, etc.)1445. Document runbooks for deployment, rollback, and incident response1456. Test disaster recovery procedures regularly146147## Red Flags148149- **Infrastructure changes without review**: Unreviewed changes cause outages — use PRs for infra code150- **No rollback strategy**: Every deployment needs a tested rollback plan before it runs151- **Secrets in configuration files**: Secrets in YAML/JSON get committed to version control152- **Missing monitoring and alerting**: Without monitoring, outages go undetected until users report them153- **No documentation for runbooks**: Without runbooks, on-call engineers waste time re-discovering procedures154155## Verification156157- [ ] Skill output matches expected behavior158159## Process1601611. Analyze the task requirements1622. Apply domain expertise1633. Verify output quality164165## Anti-Rationalization Table166167| Rationalization | Reality |168|---|---|169| "Manual deployments are fine" | Manual deployments are error-prone and不可 repeatable. Automate. |170| "We do not need monitoring" | Without monitoring, you are flying blind. Add observability from day one. |171| "Infrastructure as code is overkill" | IaC enables reproducibility, version control, and disaster recovery. |