问题描述
我正在尝试使用Jenkins构建.NET应用程序. Jenkins实例在Docker容器中运行.
I am trying to build a .NET application using Jenkins. The Jenkins instance is running in a Docker container.
我的Jenkins文件如下:
My Jenkinsfile is as follows:
pipeline {
agent {
docker {
image 'microsoft/dotnet:2.1-sdk'
registryUrl 'https://index.docker.io/v1/'
}
}
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'
}
}
}
}
当我尝试构建时,我在Jenkins构建输出中看到以下错误:
When I attempt the build I am seeing the following error in the Jenkins build output:
System.UnauthorizedAccessException: Access to the path '/.dotnet' is denied. ---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
at System.IO.FileSystem.CreateDirectory(String fullPath)
at System.IO.Directory.CreateDirectory(String path)
at Microsoft.Extensions.EnvironmentAbstractions.DirectoryWrapper.CreateDirectory(String path)
at Microsoft.DotNet.Configurer.FileSentinel.Create()
at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel, IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
似乎'.dotnet'文件夹在Docker容器中受到保护.有没有办法获得对此的读写权限,或者改变它的位置? bash进入容器时,似乎找不到该文件夹.
It appears that the '.dotnet' folder is protected in the Docker container. Is there a way of getting read/write permission on this, or a way of changing it's location? I can't seem to find the folder when I bash into the container.
感谢您的帮助.
推荐答案
该问题似乎与尝试将数据写入Docker容器('/')的顶层有关.
The issue appeared to be linked to trying to write data to the top level of the Docker container ('/').
在Jenkins文件中添加以下内容可确保设置主目录,并可以在具有正确权限的位置创建.dotnet文件夹.
Adding the following to the Jenkinsfile ensures that the home directory is set and the .dotnet folder can be created in a location with correct permissions.
environment {
HOME = '/tmp'
}
这篇关于在运行Jenkins的Docker容器中拒绝了Dotnet构建许可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!