【问题标题】:Jenkins pipeline terraform plan failing詹金斯管道地形计划失败
【发布时间】:2019-12-02 19:11:05
【问题描述】:
pipeline{
       agent any
stages{
    stage('Checkout') {
      steps {
            git branch: 'master',
                credentialsId: 'xxx-test-credentials',
                url: 'https://gitlab.com/xxxx-xxxx/xxxxx/terraform.git'

            sh "pwd"
            sh "ls -lat"
        }
    }

    stage('Set Terraform path') {
    steps {
      script {
        def tfHome = tool name: 'Terraform'
        env.PATH = "${tfHome}:${env.PATH}"
       }
       sh 'terraform version'

      }
    }

    stage('Provision infrastructure') {
        steps {
          dir('environments/dev')
          {
              withCredentials([azureServicePrincipal('xxx-test-service-principal')]) {
                  script{
                    sh  'terraform init'
                    sh  'terraform plan'
                    sh  'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID'

                    }
              }
                // sh ‘terraform destroy -auto-approve’
          }

        }
    }
  }
}

我运行了上面运行 Terraform 初始化和计划的基本管道。我已使用创建的服务主体凭据对我想要创建资源的订阅进行身份验证,但即使 Azure CLI 插件已安装在我尝试运行此管道的 Jenkins 上,我也会收到以下错误。

[1m[31mError: [0m[0m[1mError刷新状态:发生1个错误: * provider.azurerm:构建 AzureRM 客户端时出错:未找到 Azure CLI 授权配置文件。请确保已安装 Azure CLI,然后使用az login 登录。

[0米

[0m[0m[0m

【问题讨论】:

    标签: azure jenkins-pipeline jenkins-plugins terraform-provider-azure


    【解决方案1】:

    我很确定您需要先进行身份验证,然后再做计划,试试这个:

    sh  'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID'
    sh  'terraform init'
    sh  'terraform plan'
    

    【讨论】:

    • 好吧,这次是az: command not found,尽管我已经安装了 Azure cli 插件。如果az login 工作正常,运行命令的顺序可能会起作用...
    • 不,它不会因为 terraform 会尝试从 az 获取身份验证详细信息,如果您没有使用 az 登录 - 没有什么可取的。所以你需要先安装az cli
    • 是的,我需要安装 az cli 作为 jenkins docker 映像的一部分,因为 Jenkins 的 Azure cli 插件无法与 Jenkins 管道集成...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2022-11-11
    • 2019-01-09
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多