简体   繁体   中英

In Jenkins pipeline getting error “terraform: command not found”

The goal of the project is : Using terraform launch 6 AWS instance and install kafka into them, while running the terraform and ansible code manually on local its working but while tried through jenkins its throwing error.

Running a Jenkins pipeline, source code is in gitlab, I used "Execute Shell" in Build step and the code is like this :

#!/bin/bash

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

but its throwing error

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

以下是有关如何在 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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