Dotnet build permission denied in Docker container running Jenkins

后端 未结 3 1068
栀梦
栀梦 2021-02-20 11:12

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 {
          


        
3条回答
  •  天命终不由人
    2021-02-20 11:26

    Custom Docker Image, minimal changes to Jenkinsfile

    This option is good if you have the following conditions.

    1. You have multiple Jenkinsfile projects all using the same docker image.
    2. You have custom Nuget package source.

    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'
          }
        }
      }
    }
    

提交回复
热议问题