0

We are using the Lockable Resource Plugin to prevent certain parts of our jobs from running simultaneously. I'd like to allow a job to start and gather input parameters using the "Input Step" then queue while waiting for any blocking locks to clear, then proceed. Instead, I see the whole job blocking and not allowing me to enter input until all locks are cleared even though I have the Input Step outside of the Lock block.

What am I doing wrong?

Here is an example:

// Define an input step and capture the outcome from it.
def outcome = input id: 'deployment',
  message: 'Deployment Configuration',
  ok: 'Deploy',
  parameters: [
    [
      $class     : 'hudson.model.ChoiceParameterDefinition', choices: "development",
      name       : 'stack',
      description: 'select a stack to deploy'
    ],
    [
      $class     : 'hudson.model.ChoiceParameterDefinition', choices: "choice1\nchoice2",
      name       : 'profile',
      description: 'select a profile to deploy'
    ],
  ]

def profile = "${outcome.get('profile')}"
def stack = "${outcome.get('stack')}"

echo "profile: ${profile}"
echo "stack: ${stack}"

// use lockable resource to prevent multiple jobs of the same project from running at the same time.
lock(resource: "deployment") {
    sh "echo running deployment script here."
}
TreverW
  • 440
  • 7
  • 16

1 Answers1

0

Following this post Jenkins Pipeline: “input” step blocks executor I was able to solve the problem by adding

stage('deploy') {
}

around my block. For example.

// Define an input step and capture the outcome from it.
def outcome = input id: 'deployment',
  message: 'Deployment Configuration',
  ok: 'Deploy',
  parameters: [
    [
      $class     : 'hudson.model.ChoiceParameterDefinition', choices: "development",
      name       : 'stack',
      description: 'select a stack to deploy'
    ],
    [
      $class     : 'hudson.model.ChoiceParameterDefinition', choices: "choice1\nchoice2",
      name       : 'profile',
      description: 'select a profile to deploy'
    ],
  ]

def profile = "${outcome.get('profile')}"
def stack = "${outcome.get('stack')}"

stage('deploy') {
  echo "profile: ${profile}"
  echo "stack: ${stack}"

  // use lockable resource to prevent multiple jobs of the same project from running at the same time.
  lock(resource: "deployment") {
    sh "echo running deployment script here."
  }
}
Community
  • 1
  • 1
TreverW
  • 440
  • 7
  • 16