I am trying to build a .NET application using Jenkins. The Jenkins instance is running in a Docker container.
My Jenkinsfile is as follows:
pipeline {
This option is good if you have the following conditions.
If you are using a custom docker image, based off the dotnet sdk docker image. You can create a Docker file with the following.
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
WORKDIR /
# Setup default nuget.config, useful for custom nuget servers/sources
# Set Project-specific NuGet.Config files located in any folder from the solution folder up to the drive root. These allow control over settings as they apply to a project or a group of projects.
COPY nuget.config .
# Set the Environment Variable for the DOTNET CLI HOME PATH
ARG dotnet_cli_home_arg=/tmp/
ENV DOTNET_CLI_HOME=$dotnet_cli_home_arg
Create your image in the same directory as your docker file.
docker build -t jenkins-dotnet:latest .
Set your tag for the server you want to push to.
docker tag jenkins-dotnet:latest some.docker.registry/jenkins-dotnet
Push your jenkins-dotnet image to
docker push some.docker.registry/jenkins-dotnet
Then your Jenkinsfile for all of the projects could be something as follows.
pipeline {
agent {
docker {
image 'some.docker.registry/jenkins-dotnet'
registryUrl 'https://some.docker.registry'
}
}
stages {
stage('Build') {
steps {
sh 'dotnet build MyApplication/Application.csproj -c Release -o /app'
}
}
stage('Test') {
steps {
sh 'dotnet test MyApplication/Application.csproj -c Release -r /results'
}
}
}
}