在Azure Pipelines中构建ASP.NET Core项目时,下面的YAML文件仅在将解决方案和项目放在同一目录中时才起作用。无需将解决方案和项目放在同一目录中,可以对下面的YAML文件执行哪些操作?如果有multiple projects in a single solution,这一点很重要。
以下是采取的步骤:
在构建过程中导致以下错误:
复制失败:stat /var/lib/docker/tmp/docker-builder701699653/DockerTest/DockerTest.csproj:没有此类文件或目录
azure-pipelines.yml
# Docker
# Build and push an image to Azure Container Registry
# https://docs.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)
答案 0 :(得分:0)
这以前发生在我身上。
已将管道配置为在构建代理程序本身-“ docker-builder701699653”中查找您的.csproj文件。
我通过将管道的Build上下文设置为使用变量$(Build.Repository.LocalPath)
来解决了这个问题。
然后它将使用存储库构建映像。就YAML而言,我不知道在使用经典编辑器时需要设置什么。
编辑
通过构建上下文查看yaml
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)