0

我有一个通用管道将 docker 映像保存到 AWS ERC,如下所示:

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  name: Default

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1
  displayName: 'NuGetToolInstaller'

- task: NuGetCommand@2
  displayName: 'NuGetCommand'
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  displayName: 'Building Applicaton'
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  displayName: 'Running Test'
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: true
    arguments: '-c $(buildConfiguration) -o $(build.StagingDirectory)/cd-build --no-build'
    workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: Docker@2
  inputs:
    containerRegistry: 'ECR Connection'
    command: 'buildAndPush'
    Dockerfile: '**/Dockerfile'

我已经在我的系统(powershell)上设置了一个托管代理。我已经建立了 AWS 和 Docker 服务连接,但是对我来说它以一种奇怪的方式失败了......这是 Docker 日志(我已经更改了项目以隐藏我的真实姓名和公司信息):

    ##[section]Starting: Docker
    ==============================================================================
    Task         : Docker
    Description  : Build or push Docker images, login or logout, or run a Docker command
    Version      : 2.155.3
    Author       : Microsoft Corporation
    Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/docker
    ==============================================================================
    d1b8d4fc-64fc-4f82-89bb-354529799e3f exists true
    [command]"C:\Program Files\Docker\Docker\Resources\bin\docker.exe" build -f C:\Users\me\AzureDevOps\agent\_work\3\s\MyAPI\API\Dockerfile --label com.azure.dev.image.system.teamfoundationcollectionuri=https://dev.azure.com/MyOrg/ --label com.azure.dev.image.system.teamproject=TheAPI --label com.azure.dev.image.build.repository.name=TheAPI --label com.azure.dev.image.build.sourceversion=3845b7be028801bebe01da1a7a3e79ac3249cdf6 --label com.azure.dev.image.build.repository.uri=https://myorg@dev.azure.com/MyOrg/TheAPI/_git/TheAPI --label com.azure.dev.image.build.sourcebranchname=feat_continuous_deployment --label "com.azure.dev.image.build.definitionname=TheAPI CD" --label com.azure.dev.image.build.buildnumber=20190814.12 --label com.azure.dev.image.build.builduri=vstfs:///Build/Build/83572 C:\Users\me\AzureDevOps\agent\_work\3\s\MyAPI\API
    Sending build context to Docker daemon  23.04kB


    Step 1/30 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
     ---> 3ee0429b27ad
    Step 2/30 : WORKDIR /app
     ---> Using cache
     ---> a0d542531335
    Step 3/30 : EXPOSE 80
     ---> Using cache
     ---> 7d00d1b9e741
    Step 4/30 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
     ---> 3af77ac73731
    Step 5/30 : WORKDIR /src
     ---> Using cache
     ---> 6ec5981d8b1b
    Step 6/30 : COPY ["API/Web.API.csproj", "API/"]
    COPY failed: stat /var/lib/docker/tmp/docker-builder654845578/API/Web.API.csproj: no such file or directory
    ##[error]The process 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe' failed with exit code 1
    ##[section]Finishing: Docker

当我查找它说它丢失的文件时,我在代理文件夹中找到了它:C:\Users\me\AzureDevOps\agent_work\3\s\MyAPI\API\Web.API.csproj

查看日志,docker 正在尝试从 /var/lib/docker/tmp/docker-builder654845578/API/Web.API.csproj 复制它

也许我搞砸了设置 docker 任务并且没有在代理上提供正确的位置(老实说,没有地方将文件夹信息放在 docker 任务中)?评论/想法?

4

1 回答 1

1

我已经弄清楚了这个问题。Docker 任务模板中构建上下文的默认值为**. 我不得不将值更改为 git 项目的根文件夹值。即文件夹结构

APIRootName

    - MyAPI

        - API

            - Dockerfile

Another folder representation: APIRootName\MyAPI\API\Dockerfile

对于构建上下文值,我输入了APIRootName

于 2019-08-16T14:20:14.587 回答