Skip to content

Commit

Permalink
Add Terraform installation to PATH and add @symbol annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Zanini committed Feb 24, 2020
1 parent 71c409e commit 53aa0b5
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.plugins.terraform;


import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
Expand All @@ -22,6 +21,7 @@

import jenkins.model.Jenkins;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import java.util.List;
Expand All @@ -32,9 +32,6 @@
import java.io.IOException;
import java.io.FileNotFoundException;




public class TerraformInstallation extends ToolInstallation implements EnvironmentSpecific<TerraformInstallation>, NodeSpecific<TerraformInstallation>, Serializable {

private static final long serialVersionUID = 1L;
Expand All @@ -58,6 +55,16 @@ public TerraformInstallation forEnvironment(EnvVars environment) {
return new TerraformInstallation(getName(), environment.expand(getHome()), getProperties().toList());
}


@Override
public void buildEnvVars(EnvVars env) {
String home = getHome();
if (home == null) {
return;
}
env.put("PATH+TERRAFORM", home);
}


public String getExecutablePath(final Launcher launcher) throws IOException, InterruptedException {
return launcher.getChannel().call(new Callable<String, IOException>() {
Expand Down Expand Up @@ -89,9 +96,10 @@ public String call() throws IOException {

protected String getExecutableFilename() {
return Functions.isWindows() ? WINDOWS_EXECUTABLE : UNIX_EXECUTABLE;
}
}


@Symbol("terraform")
@Extension
public static class DescriptorImpl extends ToolDescriptor<TerraformInstallation> {

Expand Down

0 comments on commit 53aa0b5

Please sign in to comment.