-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 does not contain paths defined on /etc/environment #3695
Comments
Hello @marcuslopes! Thank you for your report. We will take a look |
Hello @marcuslopes. Thank you for your patience! Could you please create an issue in the microsoft/azure-pipelines-agent repository? |
Thank you for your time Maksim. |
Thank you! |
We continue to investigate with Marcus and we found that we have more than one issue. The PATH is not correct ( The main issue remain but we think this can be useful for others :) |
Hi @MaksimZhukov, can you jump into the discussion here microsoft/azure-pipelines-agent#3461 and help us? Thank you! |
@MaksimZhukov @ChristopheLav We looked into the issue, and there is not much we can do on the agent side. |
I came across this thread after building an image using @ChristopheLav describes the issue precisely in microsoft/azure-pipelines-agent#3461 but both this issue and Both the
However, adding this to every pipeline is not a solution. Can this issue be re-opened? |
@tonyskidmore Unfortunately, we can't see any way to fix this in our scripts as the root cause seems to be in the VMSS Custom Script Extension behavior. |
I have been working on a three part blog series on Azure DevOps Self-Hosted VMSS Agents. I looked at this issue again while working through that and came up with a workaround that seems to work for me, based on various comments in the history of this issue. Specifically, in the PATH issue in Part 2 I mention what I did to workaround this. Would be interested to get any feedback. |
Hi @miketimofeev, @kuleshovilya, @MaksimZhukov @marcuslopes @ChristopheLav |
While testing our self-hosted GitHub runners on a rust repository, it failed with: line 1: cargo: command not found I found out it related to $PATH environment variable, and it revealed additional issues. First when I run `echo $PATH` it printed: PATH=$HOME/.local/bin:/opt/pipx_bin:$HOME/.cargo/bin:....:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin Also `echo $HOME` prints "/home/runner". I couldn't understand why cargo command not found at the beginning. Then I learned in Unix-like operating systems the `PATH` environment variable is just a string that holds a list of directories separated by colons (`:`). Variable substitution does occur at the moment of assignment. I found similar issues (actions/runner-images#3695 (comment)) Some configuration files such as $PATH related to the user's home directory need to be changed. We need to run post-generations scripts after first boot to configure them. https://github.com/actions/runner-images/blob/main/docs/create-image-and-azure-resources.md#post-generation-scripts Post-generation scripts use latest record at /etc/passwd as default user. We need to reconnect to vm to reload environment variables, so we invalidate ssh cache. This change alone was not enough. I noticed $PATH inside at workflow job was printed as: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin After some research I found another issue: microsoft/azure-pipelines-agent#3461 runner script doesn't use global $PATH variable by default. It gets path from secure_path at /etc/sudoers. Changing sudoers files isn't a good thing to do. Also script load .env file, so we are able to overwrite default path value of runner script with $PATH. After solving these two puzzling issues, runner script is able to load correct $PATH value. /home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:...:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
While testing our self-hosted GitHub runners on a rust repository, it failed with: line 1: cargo: command not found I found out it related to $PATH environment variable, and it revealed additional issues. First when I run `echo $PATH` it printed: PATH=$HOME/.local/bin:/opt/pipx_bin:$HOME/.cargo/bin:....:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin Also `echo $HOME` prints "/home/runner". I couldn't understand why cargo command not found at the beginning. Then I learned in Unix-like operating systems the `PATH` environment variable is just a string that holds a list of directories separated by colons (`:`). Variable substitution does occur at the moment of assignment. I found similar issues (actions/runner-images#3695 (comment)) Some configuration files such as $PATH related to the user's home directory need to be changed. We need to run post-generations scripts after first boot to configure them. https://github.com/actions/runner-images/blob/main/docs/create-image-and-azure-resources.md#post-generation-scripts Post-generation scripts use latest record at /etc/passwd as default user. We need to reconnect to vm to reload environment variables, so we invalidate ssh cache. This change alone was not enough. I noticed $PATH inside at workflow job was printed as: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin After some research I found another issue: microsoft/azure-pipelines-agent#3461 runner script doesn't use global $PATH variable by default. It gets path from secure_path at /etc/sudoers. Changing sudoers files isn't a good thing to do. Also script load .env file, so we are able to overwrite default path value of runner script with $PATH. After solving these two puzzling issues, runner script is able to load correct $PATH value. /home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:...:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
While testing our self-hosted GitHub runners on a rust repository, it failed with: line 1: cargo: command not found I found out it related to $PATH environment variable, and it revealed additional issues. First when I run `echo $PATH` it printed: PATH=$HOME/.local/bin:/opt/pipx_bin:$HOME/.cargo/bin:....:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin Also `echo $HOME` prints "/home/runner". I couldn't understand why cargo command not found at the beginning. Then I learned in Unix-like operating systems the `PATH` environment variable is just a string that holds a list of directories separated by colons (`:`). Variable substitution does occur at the moment of assignment. I found similar issues (actions/runner-images#3695 (comment)) Some configuration files such as $PATH related to the user's home directory need to be changed. We need to run post-generations scripts after first boot to configure them. https://github.com/actions/runner-images/blob/main/docs/create-image-and-azure-resources.md#post-generation-scripts Post-generation scripts use latest record at /etc/passwd as default user. We need to reconnect to vm to reload environment variables, so we invalidate ssh cache. This change alone was not enough. I noticed $PATH inside at workflow job was printed as: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin After some research I found another issue: microsoft/azure-pipelines-agent#3461 runner script doesn't use global $PATH variable by default. It gets path from secure_path at /etc/sudoers. Changing sudoers files isn't a good thing to do. Also script load .env file, so we are able to overwrite default path value of runner script with $PATH. After solving these two puzzling issues, runner script is able to load correct $PATH value. /home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:...:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
While testing our self-hosted GitHub runners on a rust repository, it failed with: line 1: cargo: command not found I found out it related to $PATH environment variable, and it revealed additional issues. First when I run `echo $PATH` it printed: PATH=$HOME/.local/bin:/opt/pipx_bin:$HOME/.cargo/bin:....:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin Also `echo $HOME` prints "/home/runner". I couldn't understand why cargo command not found at the beginning. Then I learned in Unix-like operating systems the `PATH` environment variable is just a string that holds a list of directories separated by colons (`:`). Variable substitution does occur at the moment of assignment. I found similar issues (actions/runner-images#3695 (comment)) Some configuration files such as $PATH related to the user's home directory need to be changed. We need to run post-generations scripts after first boot to configure them. https://github.com/actions/runner-images/blob/main/docs/create-image-and-azure-resources.md#post-generation-scripts Post-generation scripts use latest record at /etc/passwd as default user. We need to reconnect to vm to reload environment variables, so we invalidate ssh cache. This change alone was not enough. I noticed $PATH inside at workflow job was printed as: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin After some research I found another issue: microsoft/azure-pipelines-agent#3461 runner script doesn't use global $PATH variable by default. It gets path from secure_path at /etc/sudoers. Changing sudoers files isn't a good thing to do. Also script load .env file, so we are able to overwrite default path value of runner script with $PATH. After solving these two puzzling issues, runner script is able to load correct $PATH value. /home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:...:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Description
When running a task inside a self-hosted Ubuntu build agent (either manual or automatic scaleset), running
echo $PATH
on a self hosted agent returns a very limited number of paths.Connecting to the agent via SSH and running
echo $PATH
directly will return the full range of paths inside the PATH variable though.I am not sure if this can help in the troubleshooting, but I have noticed that even though my image was generated via this repo, there are comment lines and possibly extra config in MS-hosted agents in files like ~/.profile that are not present in my self-hosted agent. I wonder if there would be some extra configuration necessary that is done outside of the image generation scripts available in this repo.
Example of differences between my image's ~/.profile and the MS-hosted one:
self-hosted:
mesg n || true
MS-hosted:
Virtual environments affected
Image version and build link
Ubuntu 18
Image version: releases/ubuntu18/20210606 commit 58b026c
Agent version: 2.187.2
Ubuntu 20
Image version: releases/ubuntu20/20210606 commit a26b241
Agent version: 2.188.3
Packer: 1.6.2, 1.7.2
Is it regression?
No response
Expected behavior
Running a shell script task
echo $PATH
on a self hosted Ubuntu agent should return all of the paths defined inside the /etc/environment file:PATH=/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$HOME/.local/bin:/opt/pipx_bin:/usr/share/rust/.cargo/bin:$HOME/.config/composer/vendor/bin:/usr/local/.ghcup/bin:$HOME/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Actual behavior
Running a shell script task
echo $PATH
on a self hosted Ubuntu agent returns a very limited number of paths:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
If I perform the following steps, $PATH gets filled as expected though:
/opt/vsts/a1
Repro steps
echo $PATH
The text was updated successfully, but these errors were encountered: