gpt4 book ai didi

Azure DevOps Build Pipeline 适用于具有多种项目类型的解决方案

转载 作者:行者123 更新时间:2023-12-04 15:59:45 25 4
gpt4 key购买 nike

我有一个包含以下内容的解决方案

  • 几个 Asp.net 项目(微服务和网关)

  • .Net Core + Angular 8(前端)

当我点击 Visual Studio 中的构建按钮时,每个项目都会构建。我已经创建了一个存储库并上传了解决方案。现在,我正在尝试弄清楚如何设置管道来构建每个微服务并将它们部署到单独的 Azure Web 应用程序。

我有以下 Angular 项目的管道。我应该像这样定义单独的任务吗?有没有办法在这里复制 Visual Studio 构建?

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
vmImage: 'windows-latest'

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

steps:
- task: NuGetToolInstaller@1

- task: Npm@1
inputs:
command: install
workingDir: 'd:\a\1\s\Ok.Web\ClientApp'

- task: Npm@1
inputs:
command: custom
workingDir: 'd:\a\1\s\Ok.Web\ClientApp'
customCommand: run build

- task: CopyFiles@2
inputs:
targetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1

最佳答案

您可以在此处应用两种方法之一:

  1. 整个存储库的一个管道
  2. 一个项目的管道

在这两种情况下,您都可以使用模板来避免重复;因此,您将定义构建 .NET 项目的常见任务,然后在管道中使用它们。我最近发表了一篇关于 this 的博文,但请看一下documentation也是。

要实现此目的,您需要首先定义一个包含常见步骤的 YAML 文件。例如:

parameters:
- name: buildConfiguration # name of the parameter; required
default: 'Release'
- name: projectFolder
default: ' '

steps:

- task: DotNetCoreCLI@2
displayName: Restore nuget packages
inputs:
command: restore
projects: '*.csproj'
workingDirectory: '${{ parameters.projectFolder}}'

- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: '${{ parameters.projectFolder}}'
arguments: '--configuration ${{ parameters.buildConfiguration }}'

# You just added coverlet.collector to use 'XPlat Code Coverage'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '*Tests/*.csproj'
arguments: '--configuration ${{ parameters.buildConfiguration }} --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true'
workingDirectory: '${{ parameters.projectFolder}}'

- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool

- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:${{ parameters.projectFolder}}/coverlet/reports -reporttypes:"Cobertura"
displayName: Create reports

- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: ${{ parameters.projectFolder}}/coverlet/reports/Cobertura.xml

然后从主构建文件中调用此文件:

variables:
buildConfiguration: 'Release'
projectFolder: 'path to your project'

steps:

- template: build-and-test.yaml
parameters:
buildConfiguration: $(buildConfiguration)

- script: echo Some steps to create artifacts!
displayName: 'Run a one-line script'

在方法 1 中,即使只更改一个项目,您也将构建所有项目,因此我建议您使用方法 2。为此,您可以定义多个管道(每个项目一个)并将触发器限制为特定文件夹中的更改。请看一下here .

这里有一个示例,说明如何将触发器限制到主分支的特定文件夹:

trigger:
branches:
include:
- master
paths:
include:
- gated-checkin-with-template/*
exclude:
- gated-checkin-with-template/azure-pipelines-gc.yml

关于Azure DevOps Build Pipeline 适用于具有多种项目类型的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61117098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com