Error: spawn terraform ENOENT during Azure Pipeline Terraform

Error: spawn terraform ENOENT during Azure Pipeline Terraform

当尝试 运行 terraform init 作为 Azure Pipeline 中的任务时,它会出错并显示

spawn C:\hostedtoolcache\windows\terraform[=15=].12.7\x64\terraform.exe ENOENT

安装看起来很好,因为在安装步骤中验证了基本功能 (terraform version)

相关管道任务

...
  - task: TerraformInstaller@0
    displayName: 'Install Terraform 0.12.7'
    inputs:
      terraformVersion: 0.12.7
  - task: TerraformTaskV1@0
    displayName: 'Terraform : init'
    inputs:
        command: 'init'
        workingDirectory: '$(System.DefaultWorkingDirectory)/Terraform/terraform'
...

安装 Terraform 0.12.7

...
Verifying Terraform installation...
C:\hostedtoolcache\windows\terraform[=11=].12.7\x64\terraform.exe version
Terraform v0.12.7

Your version of Terraform is out of date! The latest version
is 0.12.19. You can update by downloading from www.terraform.io/downloads.html
Finishing: Install Terraform 0.12.7

地形:初始化

...
C:\hostedtoolcache\windows\terraform[=12=].12.7\x64\terraform.exe validate
##[error]Error: There was an error when attempting to execute the process 'C:\hostedtoolcache\windows\terraform[=12=].12.7\x64\terraform.exe'. This may indicate the process failed to start. Error: spawn C:\hostedtoolcache\windows\terraform[=12=].12.7\x64\terraform.exe ENOENT
Finishing: Terraform : validate

许多其他用户报告通过添加结帐步骤成功修复了此问题,但管道会自动执行此操作(大概以前的版本没有),手动添加它没有效果(由于选项不同,实际花费了 2 秒的时间)。

原来工作目录路径不正确,因为目录结构已更改。

将所有命名的工作目录从 Terraform/terraform 更改为仅 terraform 更正了该问题。

大概在这种情况下以及未执行 checkout 的情况下,Terraform 根本无法定位 main.tf,但错误丢失或丢失。

当我重命名发布管道工件并且没有重新推送代码时,我偶然发现了这个错误,因此导致缓存没有失效。