Craig
Craig

Reputation: 177

Jenkins dotnet command not found

I am trying to setup CI locally with Jenkins on OSX, however I am having some issues when trying to execute shell commands. Here are the commands I am trying to run in the Jenkins configuration:

cd /Users/username/projectname
dotnet build HD-Project.sln

However, when I try and build the project, I get the following errors:

Building in workspace /Users/Shared/Jenkins/Home/workspace/HD-Build
[HD-Build] $ /bin/sh -xe 
/Users/Shared/Jenkins/tmp/jenkins2699993427980474696.sh
+ cd /Users/username/projectname
+ dotnet build HD-Project.sln
/Users/Shared/Jenkins/tmp/jenkins2699993427980474696.sh: line 3: 
dotnet: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Any help would be greatly appreciated, thanks.

Upvotes: 12

Views: 12864

Answers (4)

Khaled Gomaa
Khaled Gomaa

Reputation: 99

I had the same issue and I'd like to give you the steps that worked with me.

First of all you need to understand the issue:

  • Simply after installing the .NETSDK the path of dotnet executable file has not been added to the environment variable $PATH so you need to add it manually.

#step 1: Run the following command to execute some bash commads

  • docker exec -it jenkins-master bash. Where "jenkins-master" is your container name

#step 2: Find the dotnet path

  • run the following command to get the dotnet path

    find / -name dotnet -type f 2>/dev/null

#step 3: Add the path to your $PATH variable

  • run the following command:

    export PATH=$PATH:/var/jenkins_home/tools/io.jenkins.plugins.dotnet.DotNetSDK/dotnetsdk/

Now you can run "echo $PATH". Then you can find that the new path of dotnet has been added.

But there is an issue since the docker container is ephemeral by default the new added path will not be persisted once you exit the bash so to fix it we need to persist it.

#step 4: Persist the dotnet path to $PATH variable

  • cat >> ~/.bashrc <<EOL export PATH=$PATH:/var/jenkins_home/tools/io.jenkins.plugins.dotnet.DotNetSDK/dotnetsdk/ EOL

#step 5: Restart the container

Now It's time to try you will be able to use dotnet without to get the full path of the executable file.

Hope you find it useful.

Upvotes: 0

Hp93
Hp93

Reputation: 1535

For those that use Docker container, follow this article: https://medium.com/@nestor.panu/building-an-asp-net-6-application-on-docker-based-jenkins-d6c8aaf94756

Basically:

  1. Install these Jenkins plugins: MSBuild and .NET SDK Support
  2. Go to Jenkins config page, under the new .NET SDK section, add a new SDK of your choice (.NET 6 for example)
  3. Inside your Jenkins job, make sure you selected the .NET SDK you created in step 2
  4. Also select one of the wrapper build that comes with .NET SDK Support
  5. Run your job.
  6. If you run into error 134, install libicu-dev on the docker container.

Upvotes: 0

stepheaw
stepheaw

Reputation: 1713

This happens because the installation package does not add the dotnet executable location to the PATH environment variable. This issue is mentioned in https://github.com/dotnet/core/blob/master/cli/known-issues.md#users-of-zsh-z-shell-dont-get-dotnet-on-the-path-after-install, but apparently it does not affect only zsh users. You need to add this path manually.

In my case the path was /usr/local/share/dotnet, so I ran (from the command line):

export PATH=/usr/local/share/dotnet:$PATH

Taken from https://github.com/dotnet/cli/issues/4357

Upvotes: 2

fuzzi
fuzzi

Reputation: 2277

I got this working, and was successfully able to run dotnet commands through an executed shell via Jenkins.

To run dotnet commands, the .NET SDK needs to be installed on the Jenkins build server. Instructions on how to install the .NET SDK can be found here: https://www.microsoft.com/net/learn/get-started/macos for all OS - Linux, MacOS and Windows.

Upvotes: 5

Related Questions