Skip to content
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

Adding environment variables support to Builder.class #115

Conversation

danyShapiro
Copy link

Hi,
I am developing Che Builder that should be able to execute build requests while the execution relies on environment variables.
i.e. the commands that are going to be executed by the builder read some information from the environment variables.
Hence the environment variables should be updated before the build execution dynamically for every build.

Following current implementation the information could be passed to the builder using the BuildRequest, but as I see it, update of the environment variables before the build execution is missing.
So I'm proposing to add the following method to the Builder.class

public Map<String, String> getEnvironmentVariables (){
return new HashMap<String, String>();
}

Any implementing builder class can override this method , by default it will be empty .
so that in Line 440 in Builder.class ,the code could be changed to the following :

ProcessBuilder processBuilder = new ProcessBuilder().command(commandLine.toShellCommand()).directory(
configuration.getWorkDir()).redirectErrorStream(true);

HashMap<String, String> env = processBuilder.environment();
env. putAll(getEnvironmentVariables());

Process process = processBuilder.start();

This way the command executed by the builder will be able to use the environment variables passed in to the builder using the BuildRequest.

Thanks
Dany.

Change-Id: Ibeeeee904a530119f2fb637eabea94f6a92bdc0b
adding functionalty to update/change the env for processBuilder,
by default returns unchaged, extrending classes can override 

Change-Id: Ifa8e1f630f0a36ff2b7708c2d56459cfca1b5969
@skabashnyuk
Copy link
Contributor

Can we do that without exposing additional method ?
public Map<String, String> updateEnvironmentVariables(Map<String, String> env)

@danyShapiro
Copy link
Author

Hi,
Additional alternative solution can be to "piggy back" the BuilderConfiguration object .
i.e the createCommandLine will update the configuration internally (in additional field ) and when the
configuration is passed to execute(...) and then to createTaskFor (...) the processBuilder will be updated from configuration using updateEnvironmentVariables(..) that i will change to private.

Do you prefer this solution ?
If have other ideas , do tell ...

BR.
Dany.

…#115)

Alternative solution , "piggy back" the BuilderConfiguration object .
i.e The createCommandLine Builder implementation updates the
configuration internally (if needed),
when the configuration is passed to execute(...) and then to
createTaskFor (...) the processBuilder will be updated from
configuration using updateEnvironment(..) , only if configuration
provides values.
@skabashnyuk
Copy link
Contributor

@danyShapiro can you make this pr up to date?

@skabashnyuk
Copy link
Contributor

Closed as outdated.

@skabashnyuk skabashnyuk closed this Sep 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants