Agent directives
agent any
agent {
docker {
image 'node:20-alpine'
args '-v /tmp:/tmp'
}
}
agent { label 'linux && docker' }
agent none // set agent per stageParallel stages
stage('Tests') {
parallel {
stage('Unit') {
steps { sh 'npm run test:unit' }
}
stage('Integration') {
steps { sh 'npm run test:integration' }
}
stage('Lint') {
steps { sh 'npm run lint' }
}
}
}when — conditional stages
stage('Deploy') {
when {
branch 'main'
}
steps {
sh './scripts/deploy.sh'
}
}input — manual approval
stage('Deploy to Production') {
input {
message 'Deploy to production?'
ok 'Yes, deploy!'
submitter 'admin,lead-dev'
}
steps {
sh './deploy-prod.sh'
}
}Wrap with a timeout so builds do not hold an executor forever:
timeout(time: 1, unit: 'HOURS') {
input message: 'Deploy?'
}