Dotnet build permission denied in Docker container running Jenkins

后端 未结 3 1088
栀梦
栀梦 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条回答
  •  梦毁少年i
    2021-02-20 11:30

    You can set the HOME environment variable as @colmulhall suggested, but then you will set the docker container home directory to /tmp.

    To do it in "dotnet" way set the environment variable DOTNET_CLI_HOME:

    environment {
        DOTNET_CLI_HOME = "/tmp/DOTNET_CLI_HOME"
    }
    

    Or before calling dotnet run:

    export DOTNET_CLI_HOME="/tmp/DOTNET_CLI_HOME"
    


    Update

    A sample Jenkins pipeline code taken from https://www.jenkins.io/doc/pipeline/tour/environment/

    Look how DOTNET_CLI_HOME is defined in the environment section:

    pipeline {
        agent {
            label '!windows'
        }
    
        environment {
            DISABLE_AUTH = 'true'
            DB_ENGINE    = 'sqlite'
            DOTNET_CLI_HOME = "/tmp/DOTNET_CLI_HOME"
        }
    
        stages {
            stage('Build') {
                steps {
                    echo "Database engine is ${DB_ENGINE}"
                    echo "DISABLE_AUTH is ${DISABLE_AUTH}"
                    sh 'printenv'
                }
            }
        }
    }
    

    There are many ways to achieve this. If you are using docker, maybe a better way is defining the environment variable DOTNET_CLI_HOME in the docker image.

提交回复
热议问题