Reputation: 1603
I'm trying to run a terraform test in Jenkins. Here's what I have done:
Installed terraform plugin
Added a terraform installation in global tools
Added a freestyle project.
In build environment I added terraform
In build I added "execute shell" with the following commands: pwd, ls -la, terraform init
Whenever I try to run this build I get the following:
Building in workspace /Users/david.bien/.jenkins/workspace/terraform
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/killabien/terra.git # timeout=10
Fetching upstream changes from https://github.com/killabien/terra.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/killabien/terra.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision d1be254f44ab29acd0a5eb6cab06db0e78b21ff5 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f d1be254f44ab29acd0a5eb6cab06db0e78b21ff5
Commit message: "removed jenkins file"
> git rev-list --no-walk d1be254f44ab29acd0a5eb6cab06db0e78b21ff5 # timeout=10
[terraform-plugin] $ /Users/david.bien/.jenkins/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/terraform/terraform get
[terraform] $ /bin/sh -xe /var/folders/71/nc43yr_d4gj3z96vsnhf6xrc0000gn/T/jenkins7852414313721362731.sh
+ pwd
/Users/david.bien/.jenkins/workspace/terraform
+ ls -la
total 8
drwxr-xr-x 7 david.bien staff 238 Apr 6 12:53 .
drwxr-xr-x 5 david.bien staff 170 Apr 6 12:50 ..
drwxr-xr-x 12 david.bien staff 408 Apr 6 13:05 .git
drwxr-xr-x 4 david.bien staff 136 Apr 6 12:50 .terraform
-rw-r--r-- 1 david.bien staff 242 Apr 6 12:50 main.tf
drwxr-xr-x 4 david.bien staff 136 Apr 6 12:50 modules
drwxr-xr-x 5 david.bien staff 170 Apr 6 13:05 terraform-plugin
+ terraform init
/var/folders/71/nc43yr_d4gj3z96vsnhf6xrc0000gn/T/jenkins7852414313721362731.sh: line 4: terraform: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I understand that it doesn't see the terraform but how else can I make it see it? I'm using a github repo for the source. I want to make a step for each terraform command: init, plan and apply. How can I achieve this is Jenkins? I couldn't find any tutorial explaining this bit. Thanks.
Upvotes: 0
Views: 3937
Reputation: 904
On your build environment you need to find out where terraform is installed and ensure that is on the path. If not you need to add the directory to the agent path on Jenkins.
Upvotes: 4