Windows builds, refreshenv: command not found

I am in need to refresh PATH or JAVA_HOME after installing a JDK using choco install openjdk11 -y.

If I set evn: JAVA_HOME="...." manually it works just fine but I have to hardcode the path to the specific version of the JDK, which is not ideal.

refreshenv command seems to be the ideal solution and everywhere it is said to just call it and you are done, but when calling it inside a Travis Windows build I get: refreshenv: command not found.

I then decided to copy-paste the refreshenv code into a file in the project and call it from there. It gets actually called correctly, but it does not refresh the environment.

Any advice?

See my similar answer to another question about using RefreshEnv.cmd: Install location for iisexpress

1 Like

In the end I solved using Gravis, but thank you for the answer :slight_smile:

Is there a proper solution for this? I have the same problem with choco install awscli, however I can’t call awscli using the mentioned cmd.exe solution (cmd.exe //c "RefreshEnv.cmd & ...) because it’s called directly from some node.js code somewhere.

Proper? I don’t know. But I have come up with a single line approach that works for me:

eval $(powershell -NonInteractive -Command 'write("export PATH=`"" + ([Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [Environment]::GetEnvironmentVariable("PATH","User")).replace("\","/").replace("C:","/c").replace(";",":") + ":`$PATH`"")')

This is not a complete replacement for refreshenv, so I only call it “refreshpath”.

With YAML anchors, it also works nicely in my travis configuartion, e.g.:

_anchors:
  - &refreshpath eval $(powershell -NonInteractive -Command 'write("export PATH=`"" + ([Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [Environment]::GetEnvironmentVariable("PATH","User")).replace("\","/").replace("C:","/c").replace(";",":") + ":`$PATH`"")')

os: windows
language: shell
before_install:
  - choco install openjdk python3
  - *refreshpath
  - python --version
  - pip --version
  - java -version
Imprint