/ QUICK TIPS , LINUX

TFS Linux Agent with error: The user's home directory could not be determined

How to fix problem with dotnet restore on TFS 2017 Linux agent - The user’s home directory could not be determined.

I have recently configured Linux agent for Team Foundation Server 2017 to be able to run dotnet core project there. But during dotnet restore step error was thrown: Error: /usr/bin/dotnet failed with return code: 1 with more explanation: The user’s home directory could not be determined. Set the ‘DOTNET_CLI_HOME’ environment variable to specify the directory to use. It may occur also on newer versions of TFS and on its online version - Visual Studio Team Services (VSTS), currently called Azure DevOps.

After quick search I knew that dotnet needs to know where home is located for some operations.

Agent logs

Full agent logs for dotnet restore step:

[section]Starting: Restore
==============================================================================
Task         : .NET Core
Description  : Build, test and publish using dotnet core command-line.
Version      : 1.0.1
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
==============================================================================
[command] /usr/bin/dotnet restore /home/tfs-agent/PS-TFS-AGENT-LNX01_agent01/_work/2/s/ProjectName/ProjectName.csproj
The user's home directory could not be determined. Set the 'DOTNET_CLI_HOME' environment variable to specify the directory to use.
[error] Error: /usr/bin/dotnet failed with return code: 1
[error] Dotnet command failed with non-zero exit code on the following projects : /home/tfs-agent/PS-TFS-AGENT-LNX01_agent01/_work/2/s/ProjectName/ProjectName.csproj
[section] Finishing: Restore

What didn’t help

First I checked if $HOME variable can be seen on this Linux Machine, logged in as user which is given for TFS. It was ok. Then I set DOTNET_CLI_HOME as Linux environment variable, pointing to $HOME. It didn’t help. There were much more solutions to check, looking through the internet, but next one worked for me.

Solution

This solutions is not elegant, but it works and in my view is acceptable, and it has one big advantage - it doesn’t require access to Linux Machine ssh. I set DOTNET_CLI_HOME as build definition variable, pointing to /tmp directory. That’s it, now dotnet restore and build works :) TFS 2017 build definition variables screenshot

Summary

I don’t know if this solution will work for everyone, but it takes only 2 clicks to try, so definitely it’s good to start with :)

tometchy

Tometchy

Passionate focused on agile software development and decentralized systems

Read More