How to Gate a Production Deploy With Input and Timeout in Jenkins
Wrap the input step in timeout so an unanswered production approval aborts instead of holding an executor.
Put the input approval inside a timeout block and run it on agent none so the pipeline does not hold an executor while it waits for a human.
Steps
- Add an approval stage with
agent noneso it does not occupy an executor. - Wrap the
inputstep in atimeoutblock. - On approval, run the deploy stage; on timeout the run aborts.
Pipeline
Jenkinsfile
pipeline {
agent any
stages {
stage('Approve') {
agent none
steps {
timeout(time: 30, unit: 'MINUTES') {
input message: 'Deploy to production?', ok: 'Deploy', submitter: 'release-team'
}
}
}
stage('Deploy') {
steps { sh './deploy.sh --env prod' }
}
}
}Gotchas
- An unwrapped
inputwaits indefinitely; thetimeoutis what guarantees the run ends. - Use
submitterto restrict who can approve the production deploy.
Related guides
How to Deploy to Multiple Environments With Parameters in JenkinsLet an operator pick the target environment for a Jenkins deploy with a choice parameter, then map that choic…
How to Use the credentials() Helper for Prod Secrets in JenkinsInject production secrets into a Jenkins deploy with the credentials() helper in an environment block, bindin…