繁体   English   中英

Azure DevOps 管道无法找到可执行文件:“terraform”

[英]Azure DevOps Pipeline unable to locate executable file: 'terraform'

我试图在 Azure DevOps 中设置一个管道,它启动一个 Azure 资源组。 其配置保存在 DevOps 存储库的 a.tf 文件中。

管道是使用经典编辑器创建的。 以下任务以相同的顺序添加到作业代理:terraform init (Terraform CLI) 和 Build Project (.NET Core)。

Terraform 已安装(文件路径添加到环境变量)。

我对此很陌生,正在尝试迈出第一步。 所以任何帮助将不胜感激。 另外,如果缺少任何重要信息,您可以告诉我。

这是 Terraform 初始化任务的作业代理日志:

2023-01-19T15:15:19.3880770Z ##[section]Starting: terraform init
2023-01-19T15:15:19.3895740Z ==============================================================================
2023-01-19T15:15:19.3896080Z Task         : Terraform CLI
2023-01-19T15:15:19.3896240Z Description  : Execute terraform cli commands
2023-01-19T15:15:19.3896440Z Version      : 0.7.8
2023-01-19T15:15:19.3896590Z Author       : Charles Zipp
2023-01-19T15:15:19.3896770Z Help         : 
2023-01-19T15:15:19.3896890Z ==============================================================================
2023-01-19T15:15:21.3070520Z ##[error]Error: Unable to locate executable file: 'terraform'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
2023-01-19T15:15:21.3186320Z ##[error]Error: Unable to locate executable file: 'terraform'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
2023-01-19T15:15:21.5201550Z ##[section]Finishing: terraform init

我尝试在各种后端类型设置中运行它。 也曾多次尝试更改代理规范。 此外,在将 terraform.exe 放入存储库根目录后,我是否尝试过运行它。

我的预期是管道会创建一个新的资源组,但任务甚至不会执行。

看起来您正在使用Azure 管道 Terraform 任务扩展 Azure DevOps,其中还包括 Terraform 的安装程序任务,称为“ TerraformInstaller ”。 尝试在“terraform init”之前将其添加到您的管道中,以确保安装了 Terraform(默认情况下它将安装最新版本,除非您给它一个特定的版本)并且对于代理的操作系统是正确的。

至于为什么找不到现有的 terraform 二进制文件,我的猜测是您一直在尝试使用 windows 版本的 terraform ( terraform.exe ) 而不是 linux 版本,它只是terraform在管道上运行linux代理。 我猜这是因为任务的 output 说它找不到没有.exe扩展名的名为terraform的文件。

问题解决了。 两种解决方案:

  1. 在添加其他 Terraform 任务之前,将 Terraform 安装任务添加到管道中。 您可以在上面批准的答案中找到有用的链接。

  2. 使用 Ubuntu(我猜是任何版本)代理运行管道(管道 -> 代理规范 -> ubuntu-latest)。

我更喜欢第二种解决方案,因为 ubuntu 代理完成任务的速度明显快于 Microsoft 代理(而不是因为添加的安装任务只用了 7 秒)。 用于比较: Ubuntu 代理:1 分 16 秒(第一次执行;之后的执行总共约 30 秒) Windows 代理:4 分 31 秒

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM