Jenkinsfile · Lesson 6 of 10 · 3 min read
Approvals and promotion
The input directive (preferred) vs input step
stage('Approve production') {
agent none // no executor held while waiting
when { branch 'main'; beforeInput true }
options { timeout(time: 24, unit: 'HOURS') } // auto-abort if nobody approves
input {
message 'Deploy orders to production?'
ok 'Deploy'
submitter 'release-managers,platform-leads' // users or groups allowed to approve
parameters { string(name: 'CHANGE_TICKET', description: 'Change request ID') }
}
steps { echo "Approved with ticket ${CHANGE_TICKET}" }
}
Why these details matter:
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
- Don't hold an executor or pod while waiting for a human —
agent noneon the approval stage (the stage-levelinputdirective is evaluated before the agent is allocated). Waiting inside a pod agent can keep a pod running for hours. - Timeout so abandoned approvals don't pile up.
- submitter restricts who can approve — combine with folder permissions so people can't edit the Jenkinsfile to remove it (and protect the main branch).
milestonebefore/after the approval ensures an older build waiting for approval can't deploy after a newer one.
Promotion in a GitOps world
Instead of Jenkins running kubectl apply against production, the "deploy" stage updates the environment's Git config (e.g. a Kustomize overlay) and Flux applies it:
stage('Promote to staging') {
agent { kubernetes { yamlFile 'ci/pod-tools.yaml'; defaultContainer 'tools' } }
when { branch 'main' }
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'gitops-deploy-key', keyFileVariable: 'KEY')]) {
sh '''
export GIT_SSH_COMMAND="ssh -i $KEY -o StrictHostKeyChecking=accept-new"
git clone [email protected]:acme/platform-gitops.git gitops
cd gitops/apps/orders/overlays/staging
kustomize edit set image orders=$REGISTRY/orders:$GIT_COMMIT
git -c user.name=jenkins -c [email protected] commit -am "orders: staging -> $GIT_COMMIT"
git push origin HEAD:main
'''
}
}
}
Production promotion is the same change to the prod overlay — ideally via a pull request that's reviewed, giving an audit trail for free.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.