Jenkinsfile - Pipeline job stuck at input() step

Viewed 310

I'm running terraform pipeline through Jenkinsfile, where I'm using a input(...) block for the user approval, before apply. This is the code snippet:

stage('tf_plan') {

  agent {
    label: 'Jenkins-Linux-Dev'
  }

  steps {
    sh(
      label: 'Terraform Plan',
      script: '''
        #!/usr/bin/env bash
        terraform plan -input=false -no-color -out=plan.tfplan'
      '''
    )
  }
}
stage('tf_approve') {

  when { expression { return env.Action == 'apply' } }

  options {
    timeout( time: 1, unit: 'MINUTES' )
  }  
  steps {
    input(
      message: 'Proceed with above Terraform Plan??',
      ok: 'Proceed'
    )
  }
}
stage('tf_apply') {

  agent {
    label: 'Jenkins-Linux-Dev'
  }

  when { expression { return env.Action == 'apply' } }

  steps {
    sh(
      label: 'Terraform Apply',
      script: '''
        #!/usr/bin/env bash
        terraform apply -auto-approve -input=false -no-color plan.tfplan'
      '''
    )
  }
}

stage('tf_plan') is working absolutely fine but when env.Action = 'apply', it's not moving any further after stage('tf_approve'). It's stuck at Proceed or Abort step - not moving forward at all clicking either of 'em. Any idea what might be the problem?

Any help would be very much appreciated.

-S

1 Answers

My setup:

  • Jenkins 2.277.1
  • Groovy 2.3
  • Pipeline 2.6
  • Pipeline Utility Steps 2.6.1

And the following code works fine:

pipeline {
  agent any
  parameters {
    choice(choices: ['-', 'apply'], name: 'Action')
  }
  stages {
    stage('Trigger Promotion') {
      when { expression { return env.Action == 'apply' } }
      options {
        timeout( time: 1, unit: 'MINUTES' )
      }  
      steps {
        script {
          input(
            message: 'Proceed with above Terraform Plan??',
            ok: 'Proceed'
          )
        }
      }
    }
  }
}

Therefore, I don't think the issue is with the input step. Need more info on what's going on with Jenkins and its workers at that moment. Try grabbing logs of Jenkins main node.

P.S.: I'd suggest avoiding PascalCase variables in Groovy. It's usually used to declare classses

Related