Search code examples
dockerazure-devopsazure-pipelinesazure-pipelines-release-pipelineazure-devops-self-hosted-agent

Azure pipelines: Docker buildAndPush failing


I have a generic pipeline to save a docker image to AWS ERC as follows:

# 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://learn.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'

I have set up a hosted agent on my system (powershell). I have set up the AWS and Docker service connection, but it is failing in a weird way for me any how... here is the Docker log (I've change items to hid my real name and company infomation):

    ##[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://learn.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://[email protected]/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

When I look for the file it says it is missing, i found it in the agent folder: C:\Users\me\AzureDevOps\agent_work\3\s\MyAPI\API\Web.API.csproj

Looking at the logs, docker is trying to copy it from /var/lib/docker/tmp/docker-builder654845578/API/Web.API.csproj

Maybe I messed up setting up the docker task and not providing the right location on the agent (no place to put folder information in the docker task to be honest)? Comments/Ideas?


Solution

  • I've figured out the issue. The default value for ​Build context in the Docker task template is **. I had to change the value to root folder value of the git project. i.e. folder structure

    APIRootName
    
        - MyAPI
    
            - API
    
                - Dockerfile
    
    Another folder representation: APIRootName\MyAPI\API\Dockerfile
    

    For the Build context value, I've entered APIRootName