0

I have a stage in Jenkins declarative pipeline that I want to run conditionally when manually triggered, and only on the master branch.

stage('Deploy to prod') {
  when {
    branch 'master'
  }
  input {
    message "Deploy to prod?"
    ok "Deploy"
  }
  agent any
  steps {
    ..
  }
}

I'd like this stage to be skipped altogether for branches other than master, but what happens in practice is that it gets paused for all branches. Is there a way to get the behaviour I'm after?

Matt R
  • 9,892
  • 10
  • 50
  • 83

1 Answers1

1

According to the declarative pipeline doc for input

The stage will pause after any options have been applied, and before entering the stage's agent or evaluating its when condition.

To make the pipeline work the way you specified, I would convert input to a (non-declarative style) step like this:

stage('Deploy to prod') {
  when {
    branch 'master'
  }
  agent any
  steps {
    input message: "Deploy to prod?", ok: "Deploy"
    ..
  }
}
Vasiliki Siakka
  • 1,185
  • 8
  • 15