I have a self hosted build agent, which has dotnet tools and nerdbank git versioning installed. If I SSH onto the agent and run nbgv
, it exists:
agent@ip-172-18-0-30:~$ which nbgv
/home/agent/.dotnet/tools/nbgv
And I can run it:
agent@ip-172-18-0-30:~$ nbgv -h
Description:
nbgv v3.7.115+d31f50f4d1
At the start of my pipeline, I am checking the build agent user, the $HOME
env var and $PATH
env var then trying to run nbgv
:
steps:
- checkout: self
fetchDepth: 0
persistCredentials: true
- script: |
echo "Current user: $(whoami)"
echo "HOME: $HOME"
echo "PATH: $PATH"
ls -la $HOME/.dotnet/tools
dotnet tool list --global
nbgv get-version
However it is failing with nbgv: command not found
:
/usr/bin/bash --noprofile --norc /home/agent/myagent/_work/_temp/976f3776-1157-4b41-a83c-b9a2e0d5e1da.sh
Current user: agent
HOME: /home/agent
PATH: $HOME/.local/bin:/opt/pipx_bin:$HOME/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
total 84
drwxr-xr-x 3 agent agent 4096 Feb 10 13:36 .
drwxr-xr-x 3 agent agent 4096 Feb 10 13:36 ..
drwxr-xr-x 4 agent agent 4096 Feb 10 13:36 .store
-rwxr-xr-x 1 agent agent 72352 Feb 10 13:36 nbgv
Welcome to .NET 8.0!
---------------------
SDK Version: 8.0.405
Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate, view the instructions: https://aka.ms/dotnet-https-linux
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
Package Id Version Commands
-------------------------------------
nbgv 3.7.115 nbgv
/home/agent/myagent/_work/_temp/976f3776-1157-4b41-a83c-b9a2e0d5e1da.sh: line 6: nbgv: command not found
So despite $HOME
being /home/agent
and $PATH
having $HOME/.dotnet/tools
and nbgv
being in /home/agent/.dotnet/tools/nbgv
, it is failing saying it cant find nbgv
. Why is this and how do I fix it?
For reference, my user data script is:
#!/bin/bash
AGENT_USER="agent"
AGENT_HOME="/home/$AGENT_USER"
useradd -m -s /bin/bash $AGENT_USER
export VSTS_AGENT_INPUT_URL=${url}
export VSTS_AGENT_INPUT_AUTH=pat
export VSTS_AGENT_INPUT_TOKEN=${token}
export VSTS_AGENT_INPUT_POOL=${pool}
echo "export VSTS_AGENT_INPUT_URL=${url}" >> $AGENT_HOME/.bashrc
echo "export VSTS_AGENT_INPUT_AUTH=pat" >> $AGENT_HOME/.bashrc
echo "export VSTS_AGENT_INPUT_TOKEN=${token}" >> $AGENT_HOME/.bashrc
echo "export VSTS_AGENT_INPUT_POOL=${pool}" >> $AGENT_HOME/.bashrc
chown -R $AGENT_USER:$AGENT_USER $AGENT_HOME
cd $AGENT_HOME
wget https://vstsagentpackage.azureedge.net/agent/4.248.0/vsts-agent-linux-x64-4.248.0.tar.gz
mkdir myagent && cd myagent
tar zxvf ../vsts-agent-linux-x64-4.248.0.tar.gz
./bin/installdependencies.sh
chown -R $AGENT_USER:$AGENT_USER .
su $AGENT_USER -c './config.sh --unattended'
echo "HOME=$AGENT_HOME" >> .env
./svc.sh install $AGENT_USER
usermod -aG docker $AGENT_USER
./svc.sh start
mkdir -p $AGENT_HOME/myagent/_work
chown -R $AGENT_USER:$AGENT_USER $AGENT_HOME/myagent/_work
Based on your description, I could reproduce the issue when I installed nbgv
after I setup the self-hosted pipeline agent.
As suggested in this document, we need to update environment variables after installing new software.
./env.sh
sudo ./svc.sh stop
sudo ./svc.sh start