Reputation: 2270
When building an ASP.NET Core project in Azure Pipelines, the YAML file below only works when placing the solution and project in the same directory. What can be done to the YAML file below without the need of placing the solution and project in the same directory? This matters in case there are multiple projects in a single solution.
Here are the steps taken:
Which resulted in the following error during the build:
COPY failed: stat /var/lib/docker/tmp/docker-builder701699653/DockerTest/DockerTest.csproj: no such file or directory
azure-pipelines.yml
# Docker
# Build and push an image to Azure Container Registry
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'example-connection-string'
imageRepository: 'dockertest'
containerRegistry: 'example.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/DockerTest/Dockerfile'
tag: '$(Build.BuildId)'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
Upvotes: 3
Views: 994
Reputation: 1614
This has happened to me before.
The pipeline is configured to look for your .csproj file in the build agent itself - "docker-builder701699653".
I resolved this by setting the Build context of the pipeline to use the variable $(Build.Repository.LocalPath)
.
It will then use the repository to build the image. In terms of YAML I don't know what you will have to set as I use the classic editor.
EDIT
See yaml with build context
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
buildContext : $(Build.Repository.LocalPath) <----
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
Upvotes: 6