Use environment variables #173
-
Hi! I've just started to play with templates and my use case is this: I use several java versions on my machine, and the JAVA_HOME=/home/user/.asdf/installs/java/adoptopenjdk-8.0.362+9 mvn ... This lets me use the java version my project needs on every specific case. Now, I'm creating a template to automate this use case (and then chain it with some other tasks) so my component looks like this return {
...
builder = function(params)
return {
cmd = {"mvn" },
args = { "--version" },
}
end,
env = {
JAVA_HOME = "/home/user/.asdf/installs/java/adoptopenjdk-8.0.362+9",
},
condition = { dir = utils.path },
} but this doesn't set the JAVA_HOME the way I want. (I can see in the output I'm using a different jdk version). I tried several things like
or
but the task just hangs and nothing happens. Maybe this is not the correct way to pass those strings to the BTW if I don't use the env variable, the task executes successfully. Can someone kindly shed some light on this issue? :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If you check the docs for template definitions, the return {
...
builder = function(params)
return {
cmd = {"mvn" },
args = { "--version" },
env = {
JAVA_HOME = "/home/user/.asdf/installs/java/adoptopenjdk-8.0.362+9",
},
}
end,
condition = { dir = utils.path },
} |
Beta Was this translation helpful? Give feedback.
-
You're totally right. I'm sorry for my misunderstanding. But it seems that even when using the I think it's best to not define the JAVA_HOME variable this way, but to use an external tool that sets the the appropriate JAVA_HOME (because of the way I intended to use the env var: I use return {
cwd = "some path to your project where the JAVA_HOME is already defined',
cmd = { "mvn" },
args = { "--version" },
} If you really need to define env variables before the actual binary, just create a wrapper #!/bin/bash
cd /your/project/path
JAVA_HOME=/home/user/.asdf/installs/java/adoptopenjdk-8.0.362+9 mvn clean install |
Beta Was this translation helpful? Give feedback.
If you check the docs for template definitions, the
env
should be at the same level ascmd
andargs
. For example: