Skip to content
Latchkey

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 none so it does not occupy an executor.
  • Wrap the input step in a timeout block.
  • 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 input waits indefinitely; the timeout is what guarantees the run ends.
  • Use submitter to restrict who can approve the production deploy.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →