Skip to content

Inject same env variables when building container and exec command #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class BuiltInContainer implements BuildBadgeAction, EnvironmentContributi
private final transient Docker docker;
private List<Integer> ports = new ArrayList<Integer>();
private Map<String,String> volumes = new HashMap<String,String>();
private EnvVars envVars;

public BuiltInContainer(Docker docker) {
this.docker = docker;
Expand Down Expand Up @@ -84,6 +85,14 @@ public void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) {
}
}

public EnvVars getEnvVars() {
return envVars;
}

public void setEnvVars(EnvVars envVars) {
this.envVars = envVars;
}

public void bindMount(String path) {
volumes.put(path, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ private String startBuildContainer(BuiltInContainer runInContainer, AbstractBuil
try {
EnvVars environment = buildContainerEnvironment(build, listener);

runInContainer.setEnvVars(environment);

String workdir = build.getWorkspace().getRemote();

Map<String, String> links = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,9 @@ public Proc launch(ProcStarter starter) throws IOException {
private EnvVars buildContainerEnvironment() throws IOException, InterruptedException {

if (this.env == null) {
this.env = runInContainer.getDocker().getEnv(runInContainer.container, launcher);
this.env = runInContainer.getEnvVars();
}
EnvVars environment = new EnvVars(env);

// Let BuildWrapper customize environment, including PATH
for (Environment e : build.getEnvironments()) {
e.buildEnvVars(environment);
}

return environment;
return new EnvVars(env);
}

}