【问题标题】:In Jenkins pipeline getting error "terraform: command not found"在 Jenkins 管道中出现错误“terraform:找不到命令”
【发布时间】:2021-09-26 09:46:35
【问题描述】:

该项目的目标是:使用 terraform 启动 6 个 AWS 实例并将 kafka 安装到其中,同时在本地手动运行 terraform 和 ansible 代码,但通过 jenkins 尝试抛出错误。

运行 Jenkins 管道,源代码在 gitlab 中,我在 Build 步骤中使用了“Execute Shell”,代码如下:

#!/bin/bash

cd terraform-aws-ec2-with-vpc
chmod 400 oregonkeypair.pem
terraform init
terraform apply -auto-approve 

但它的抛出错误

Started by user company
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/Kafka-infra
The recommended git tool is: NONE
using credential a4eec3ff-c405-4ba6-aff2-239275a889c4
Cloning the remote Git repository
Cloning repository https://gitlab.com/company/company-cp-ansible-terraform-aws
 > git init /var/jenkins_home/workspace/Kafka-infra # timeout=10
Fetching upstream changes from https://gitlab.com/company/company-cp-ansible-terraform-aws
 > git --version # timeout=10
 > git --version # 'git version 2.20.1'
using GIT_ASKPASS to set credentials 
 > git fetch --tags --force --progress -- https://gitlab.com/company/company-cp-ansible-terraform-aws +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://gitlab.com/company/company-cp-ansible-terraform-aws # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision e1769571a021785178b84287566e625d46cf4f54 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f e1769571a021785178b84287566e625d46cf4f54 # timeout=10
Commit message: "Merge branch 'ndey1-master-patch-44242' into 'master'"
First time build. Skipping changelog.
[Kafka-infra] $ /bin/bash /tmp/jenkins1038642698264658523.sh
/tmp/jenkins1038642698264658523.sh: line 5: terraform: command not found
/tmp/jenkins1038642698264658523.sh: line 6: terraform: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

【问题讨论】:

  • 你需要在构建代理中安装terraform。

标签: amazon-web-services jenkins terraform


【解决方案1】:

以下是有关如何在 Amazon Linux/Amazon Linux 2 AMI 上安装 terraform 的文档: https://techviewleo.com/install-terraform-on-amazon-linux/ 对于 Amazon Linux 2 AMI,请确保您已应用此步骤:

sudo mv terraform /usr/local/bin/

【讨论】:

  • 我不会“mv”,而是“ln -s”
猜你喜欢
  • 1970-01-01
  • 2020-07-04
  • 1970-01-01
  • 2022-11-02
  • 2017-11-06
  • 2021-07-23
  • 2021-10-29
  • 2018-11-27
  • 2018-04-23
相关资源
最近更新 更多