Azure管道:Docker buildAndPush失败

时间:2019-08-15 18:55:27

标签: docker azure-devops azure-pipelines azure-pipelines-release-pipeline azure-devops-self-hosted-agent

我有一个通用管道将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

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

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

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。 Docker任务模板中的构建上下文的默认值为**。我必须将值更改为git项目的根文件夹值。 即文件夹结构

APIRootName

    - MyAPI

        - API

            - Dockerfile

Another folder representation: APIRootName\MyAPI\API\Dockerfile

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