-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
PATH environment variable in jenkins user cannot see java #33
Comments
Same problem here. The tag |
Same issue for me today. Seeing the above I switched to jdk11 and it works. Since I only need java to run the jenkins agent, I'd rather use the jdk8 version which is less than half the size. |
Since the jdk11 tag was updated a couple days ago, jdk11 now has the same issue |
So it is a regression in recent versions. Would be great to have it fixed indeed |
Someone should check that my previous comment is correct, since I'm new to jenkins docker plugin, and most docker concepts generally. But I had an empty test project build working on jdk11 tag on dec 23, and after the holidays (same configuration/empty test project, unchanged except jenkins auto updated my image), now cannot find java. No problems on tag "latest-jdk11" which is a year old |
Seems to be a change in where the JDK is installed. My guess is that a switch from Oracle or OpenJDK to AdoptOpenJDK or similar which had a slightly different installation procedure. As I mentioned in the ticket, you can work around the issue by manually adding the agent's |
What I think is happening here is that this line is incorrect:
This will take from the current environment all lines with an underscore in it, anywhere, and append them to For my own uses I changed that line to the following:
This takes all environment variables, except those listed, and appends then to |
@Virtlink I also did a doubletake on that line but basically wrote it off as being beyond my comprehension. I am really curious about the intention of that. Still, as random as filtering the variables by underscore seems, it would catch JAVA_HOME so I figured it wasn't the problem. You don't explicitly mention the effect of your change. Does it allow java to execute without manually specifying the path in the agent config? Does it also allow ENV declarations in the dockerfile to be available to builds (#46)? I'm a docker newbie, but if anyone can explain what it is about this project that makes such a line like |
@GunArm Let's say your call to
Doing
Note how, indeed, The command Arguably an improvement would be to just append everything from
This would include lines such as So my command does essentially the same as the original command, but selects different lines.
It selects, using
This looks like a sensible list. I think |
Great answer. Given the existence of JAVA_HOME I (unthinkingly) assumed it somehow took the place of PATH but of course it couldn't. Blacklisting known unwanted system variables (especially those known from considering the parent image) is a much better solution. |
Hello all, In fact the solution proposed by @Virtlink Works well to me too.
I had the same issue with version 8 and 11. What is the impeditive to fix the docker image with this? Just a PR or Is this solution not recommended? |
Just a PR, I'd guess |
I ran into this issue as well when running the agent from jenkins/ssh-agent:latest After launching the image, I fixed it by just updating the .bashrc file for the jenkins user like this:
Maybe the dockerfile just needs to update the .bashrc file with the PATH for java? BTW, I also tried the alpine image and ran into the same issue |
@gclayburg our of curiosity, are you using jenkins' docker-plugin to launch ephemeral build agents in jenkins builds? |
At this point, I was just following this jenkins guide. It just seemed to me the instructions were more complex than they needed to be for a simple issue like this. To me, the agent should just run without workarounds. I actually just forked this project and created a working docker image. Should I create a PR? |
Ok yeah, FYI that guide is showing use of docker-plugin. So, your solution might be a functional workaround. But there is a mechanism for this already: I believe PATH is set for the default user from the jdk base image. Getting it from the default user to the jenkins user is accounted for when the setup-sshd script "copys" the primary environment variables (all of them, not just PATH) to /etc/environment. This is not working because jenkins docker-plugin has a default of sending an sshd command to the image, and the way the script works, when it gets a command passed to it, it bypasses the part that makes the environment variables available to the jenkins user. My PR #63 resolves this issue. But it has yet to be merged. Additionally, the tweak described above, changing I'd happily add it to my PR (if it didn't further delay a release). |
yeah, that sounds reasonable, @GunArm However, I just looked at some of your work and it sounds like yours might be better in that should fix the issue for more than one docker image. I only changed the one for jdk 8 / debian buster. |
Right also, this is slightly complex because there are really two compounding issues causing the java path problem.
Also 2 is more broad of an issue than just paths, it affects all environment variables you might set in the dockerfile, like for example By all means you should use your fix until this gets sorted out, but note that it papers over the underlying problem, which has effects beyond the java path. |
@gclayburg actually on looking at your linked docker reference more closely, my apologies, I'm not sure if it is infact using docker-plugin or not. 2 in my list above might not apply to you, and the fix |
I have the same issue @Virtlink workaround fixed it for me |
@Virtlink workaround works fine. |
I use docker-compose and I wanted to have it fixed without the need to manually enter a command every time something gets restarted. Here is what I did. I created a simple
Then I modified the
Last step is to build the new image
When Jenkins web refreshed, the agent was already online! :-) |
This solution sets only JAVA_HOME and JAVA_VERSION in the /etc/environment, the PATH problem is solved by symbolic linking `java` and `javac` binaries to `/usr/local/bin`, which is always available on PATH Test suite passes.
jenkinsci/docker-ssh-agent#33 fixed by jenkinsci/docker-ssh-agent#74 Co-authored-by: Mark Waite <[email protected]> Co-authored-by: Zbynek Konecny <[email protected]>
If I run this container as root,
$JAVA_HOME/bin
is added to thePATH
. However, when I ssh in as the jenkins user, thePATH
is not propagated, and therefore the ssh-slaves plugin can't findjava
in thePATH
.My current workaround is to manually set the
javaPath
configuration value to the expected openjdk path, though this only fixes the inability to launch an agent.The text was updated successfully, but these errors were encountered: