在天蓝色的devops中构建应用程序时,无法将Data.csproj复制到Data /。不过,第一个复制命令Api.csproj到Api /可以正常工作。请注意,我没有在azure-pipeline.yml文件中指定buildContext。但是,当我确实添加了buildContext buildContext:'$(Build.Repository.LocalPath)'时,即使在第一个副本上也失败了。
关于如何解决此问题的任何意见或建议?我尝试搜索并添加buildcontext或在csproj上添加文件夹似乎不起作用。例如,COPY [“ /Data/Data.csproj”,“ Data /”]
这是我的文件夹结构(我的azure-pipeline.yml文件位于App文件夹之外):
App - Api/ - Api.csproj - Dockerfile - Data/ - Data.csproj - Domain/ - Domain.csproj - App.sln
我的dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Api.csproj", "Api/"]
COPY ["Data.csproj", "Data/"]
COPY ["Domain.csproj", "Domain/"]
RUN dotnet restore "Api/Api.csproj"
COPY . .
WORKDIR "/src/Api"
RUN dotnet build "Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Api.dll"]
我的azure-pipeline.yml的一部分
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: 'App'
dockerfile: '**/Dockerfile'
tags: |
$(tag)
这是错误:
Step 6/28 : WORKDIR /src
---> Running in 266a78d293ee
Removing intermediate container 266a78d293ee
---> 2d899fafdf05
Step 7/28 : COPY ["Api.csproj", "Api/"]
---> 92c8c1450c3c
Step 8/28 : COPY ["Data.csproj", "Data/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder764823890/Data.csproj: no such file or directory
##[error]COPY failed: stat /var/lib/docker/tmp/docker-builder764823890/Data.csproj: no such file or directory
##[error]The process '/usr/bin/docker' failed with exit code 1
答案 0 :(得分:1)
好的,尝试了很多次之后,我可以通过更改dockerfile和azure-pipelines.yml来解决此问题。
我认为解决此问题的方法是将buildContext专门设置为“ App /”而不是变量“ $(Build.Repository.LocalPath)”,我不确定确切的值是什么。
我将发布更改的部分。
Dockerfile
COPY ["Api/Api.csproj", "Api/"]
COPY ["Data/Data.csproj", "Data/"]
COPY ["Domain/Domain.csproj", "Domain/"]
azure-pipelines.yml
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
buildContext: 'App/'