[英]How build a Dockerfile in a Subdirectory using a Jenkinsfile
I have a github repository with a declarative pipeline Jenkinsfile. 我有一个带有声明性管道Jenkinsfile的github存储库。 The workingdirectory on my node contains subdirectories. 我节点上的工作目录包含子目录。
The project is a simple empty linkx docker project created with visual studio 2017 and .net core 2.1. 该项目是使用Visual Studio 2017和.net core 2.1创建的简单的空linkx docker项目。 It executes on my windows 7 machine normally and has a hello world web page. 它可以在我的Windows 7计算机上正常执行,并具有一个hello world网页。
I am unable to build the Dockerfile on jenkins. 我无法在jenkins上构建Dockerfile。 I can start the Dockerfile build using dir(...){}
. 我可以使用dir(...){}
开始Dockerfile构建。 The failing step is always 失败的步骤总是
COPY ["MyProject/MyProject.csproj", "MyProject/"]
This step requires the relative path to be in MySolution
. 此步骤要求相对路径位于MySolution
。
The file Workspace/MySolution/MyProject/MyProject.csproj
exists 文件Workspace/MySolution/MyProject/MyProject.csproj
存在
The error Message is that Workspace/MyProject/MyProject.csproj
does not exist. 错误消息是Workspace/MyProject/MyProject.csproj
不存在。
I searched exhaustively using google and stackoverflow. 我用谷歌和stackoverflow穷举搜索。 Among the things I tries are combinations of sh
commands, dir
syntax, options on docker build like -f
. 我尝试的事情包括sh
命令, dir
语法,docker build上的选项-f
。 Some of them were straigth up failures and the best results I had ran into the COPY
step issue. 其中一些是直截了当的失败,而我遇到的最佳结果就是COPY
步骤问题。
One example of a failing step in the Jenkinsfile would be: Jenkinsfile中失败步骤的一个示例是:
dir("MySolution/MyProject")
{
script
{
docker.build("MyProject", ".")
}
}
This fails with the COPY
issue from above. 由于上面的COPY
问题,此操作失败。
I have seen questions on so that seem to not quite apply here and which solutions did not transfer to this issue. 我看到了一些问题,因此似乎在这里不太适用,哪些解决方案没有解决此问题。
It turns out I ended up really close to the solution of my issue. 事实证明,我最终真的很接近问题的解决方案。 This fixed my sub folder problem: 这解决了我的子文件夹问题:
dir("MySolution")
{
script
{
docker.build("MyProject", "-f ./MyProject/Dockerfile .")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.