Reputation: 177
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
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:
#step 1: Run the following command to execute some bash commads
#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
#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
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:
MSBuild
and .NET SDK Support
.NET SDK Support
libicu-dev
on the docker container.Upvotes: 0
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
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