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, shared4 libraries, agents, stages, credentials. Use when working with jenkins pipelines.5domain: devops6author: oyi777license: Apache-2.08subdomain: devops9tags:10- ai-agent11- ci-cd12- devops13- infrastructure14- jenkins15- pipeline16- pipelines17version: 1.0.018category: devops19metadata:20 source: https://skillmd.com/skills/oyi77/jenkins-pipelines21---22232425## Overview2627Jenkins 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.2829## Capabilities3031- Declarative and Scripted pipeline authoring32- Parallel stage execution for faster builds33- Shared library development and versioning34- Credential management with Credentials plugin35- Agent/label-based build node selection36- Blue Ocean visual pipeline editor integration3738## When to Use39**Trigger phrases:**40- "jenkins pipelines"41- "Jenkins pipeline as code — Declarative/Scripted pipelines, shared libraries, age"424344- CI/CD for Java, Node.js, Python, or polyglot projects45- Complex multi-stage build/test/deploy workflows46- Teams already running Jenkins infrastructure47- Need shared pipeline logic across many repositories48- Enterprise environments with Jenkins + LDAP/RBAC4950## When NOT to Use5152- Task is outside your authorization scope53- You need to implement controls (use implementing-* skills)54- Task is about analysis, not action (use analyzing-* skills)55- You don't have access to target systems56- Task requires compliance expertise (consult professionals)57- Task is about defense, not offense (use defensive skills)585960## Pseudo Code6162The jenkins-pipelines workflow follows a standard pipeline pattern.6364Core flow:65```66# jenkins-pipelines primary flow67input = prepare(raw_data)68result = process(input, config={agents, code, credentials, declarative, jenkins})69validate(result)70deliver(result)71```7273Error handling:74```75on error:76 log(error_details)77 retry_with_backoff(max=3)78 if still_failing: alert_and_escalate()79```808182### Declarative Pipeline83```groovy84// Jenkinsfile85pipeline {86 agent { label 'linux' }87 environment {88 APP_NAME = 'my-app'89 REGISTRY = 'ghcr.io'90 }91 stages {92 stage('Build') {93 steps {94 sh 'npm ci'95 sh 'npm run build'96 }97 }98 stage('Test') {99 parallel {100 stage('Unit Tests') { steps { sh 'npm test' } }101 stage('Lint') { steps { sh 'npm run lint' } }102 }103 }104 stage('Deploy') {105 when { branch 'main' }106 steps {107 sh 'docker build -t $REGISTRY/$APP_NAME:$BUILD_NUMBER .'108 sh 'docker push $REGISTRY/$APP_NAME:$BUILD_NUMBER'109 }110 }111 }112 post {113 always { cleanWs() }114 failure { slackSend channel: '#builds', message: "FAILED: ${env.JOB_NAME}" }115 }116}117```118119### Shared Library120```groovy121// vars/deployK8s.groovy122def call(Map config) {123 sh "kubectl set image deployment/${config.app} ${config.container}=${config.image}"124 sh "kubectl rollout status deployment/${config.app}"125}126127// Jenkinsfile usage128@Library('my-shared-lib@main') _129deployK8s(app: 'api', container: 'api', image: 'ghcr.io/api:v1')130```131132### Credentials Usage133```groovy134stage('Deploy') {135 steps {136 withCredentials([string(credentialsId: 'api-key', variable: 'TOKEN')]) {137 sh 'curl -H "Authorization: Bearer $TOKEN" https://api.example.com/deploy'138 }139 withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {140 sh 'kubectl --kubeconfig=$KUBECONFIG apply -f deploy.yaml'141 }142 }143}144```145146## Common Patterns147148- **Multibranch pipeline**: auto-discovers branches with Jenkinsfile149- **Shared libraries**: reusable pipeline logic in `vars/`, `src/`, `resources/`150- **Parameters**: `parameters { string(name: 'VERSION', defaultValue: 'latest') }`151- **Input gates**: `input message: 'Deploy to production?'`152- **Matrix builds**: `matrix { axes { axis { name 'OS'; values 'linux', 'darwin' } } }`153154## How to Use1551561. Define infrastructure as code (Terraform, CloudFormation, Pulumi)1572. Review changes through PR process before applying1583. Configure monitoring and alerting for critical paths1594. Set up secrets management (Vault, AWS Secrets Manager, etc.)1605. Document runbooks for deployment, rollback, and incident response1616. Test disaster recovery procedures regularly162163## Red Flags164165- **Infrastructure changes without review**: Unreviewed changes cause outages — use PRs for infra code166- **No rollback strategy**: Every deployment needs a tested rollback plan before it runs167- **Secrets in configuration files**: Secrets in YAML/JSON get committed to version control168- **Missing monitoring and alerting**: Without monitoring, outages go undetected until users report them169- **No documentation for runbooks**: Without runbooks, on-call engineers waste time re-discovering procedures170171## Verification172173- [ ] Skill output matches expected behavior174175## Process1761771. Analyze the task requirements1782. Apply domain expertise1793. Verify output quality180181## Anti-Rationalization Table182183| Rationalization | Reality |184|---|---|185| "Manual deployments are fine" | Manual deployments are error-prone and不可 repeatable. Automate. |186| "We do not need monitoring" | Without monitoring, you are flying blind. Add observability from day one. |187| "Infrastructure as code is overkill" | IaC enables reproducibility, version control, and disaster recovery. |