【问题标题】:Jenkinsfile - Pipeline job stuck at input() stepJenkinsfile - 管道作业卡在输入()步骤
【发布时间】:2021-12-30 22:54:02
【问题描述】:

我正在通过 Jenkinsfile 运行 terraform 管道,在申请之前,我使用input(...) 块供用户批准。这是代码sn-p:

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') 工作得非常好,但是当env.Action = 'apply' 时,它在stage('tf_approve') 之后不再移动。它卡在Proceed or Abort 步骤 - 根本没有前进,点击它们中的任何一个。知道可能是什么问题吗?

非常感谢任何帮助。

-S

【问题讨论】:

    标签: terraform jenkins-pipeline jenkins-groovy terragrunt


    【解决方案1】:

    我的设置:

    • 詹金斯 2.277.1
    • Groovy 2.3
    • 管道 2.6
    • 管道实用程序步骤 2.6.1

    以下代码运行良好:

    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'
              )
            }
          }
        }
      }
    }
    

    因此,我认为问题不在于输入步骤。需要更多关于 Jenkins 及其工作人员当时的情况的信息。尝试抓取 Jenkins 主节点的日志。

    P.S.:我建议在 Groovy 中避免使用 PascalCase 变量。它通常用于声明类

    【讨论】:

    • 感谢您的回复。我对 Jenkins 的 Groovy 方面还很陌生,但我仍在努力思考。我注意到一件事:Proceed(或Abort)提供的链接似乎没有任何目标,就像:https://<jenkins_host>/jobs/my-job/150/console# - 应该是这样吗?
    • 系统日志中(对我而言)没有什么明显的地方,但在其中发现了一个异常,上面写着:Caught exception evaluating: it.transientActions in https://<jenkins_host>/jobs/my-job/150/console. Reason: java.lang.reflect.InvocationTargetException java.lang.AbstractMethodError: you must override the new overload of isApplicable in hudson.plugins.project_inheritance.projects.rebuild.RebuildValidatorSuppressor ... - 有什么关系吗?
    • 我认为问题在于您的 OP,input() 调用未包含在 script{} 块中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    • 1970-01-01
    • 2021-11-20
    • 1970-01-01
    • 2021-04-10
    相关资源
    最近更新 更多