我有一个包含多个可执行项目的
C# solution
,我想创建一个管道来构建exe文件和依赖项,以及另一个管道来使用高级安装程序生成多个安装程序。
发布管道由第一个构建管道的工件触发。正如我所注意到的,如果我不禁用它,管道就会自动开始检查存储库。我已禁用它并在第一份工作中下载工件。
我想知道是否可以只下载一次工件并使其可用于同一阶段的所有作业,而不是在所有作业中编写相同的
checkout: none
和download
。
trigger: none
pool:
name: Default
demands:
- Agent.Name -equals SelfHostedAgent
resources:
pipelines:
- pipeline: 'repoCi'
source: '\Folder\Repo-CI'
trigger: true
stages:
- stage: WPF
jobs:
- job: 'GetVersions'
steps:
- checkout: none
clean: true
- download: 'repoCi'
artifact: 'WPF'
- task: PowerShell@2
displayName: 'Get Exe Versions'
inputs:
targetType: 'inline'
script: | # Get Versions in powershell
- job: InstallerJob1
dependsOn: 'GetVersions'
condition: succeeded('GetVersions')
steps:
- checkout: none
- download: 'repoCi'
artifact: 'WPF'
- stage: Xamarin
jobs:
- job: Job1
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
Write-Host "Hello World"
在 Azure DevOps Pipelines 中,每个作业都会在代理上创建自己的工作区,在其中下载源文件和其他文件。这意味着每个作业都需要定义下载的内容和不下载的内容。没有选项可以让您全局定义为存储库中的所有作业下载哪些源/工件。
请记住,您也不一定需要将管道拆分为许多作业,您可以在单个作业中保留更多任务。当然,拥有多个作业有充分的理由,但如果您想不出一个充分的理由来说明为什么要将其拆分为多个作业,请考虑将其保留在一个作业中,以节省重复下载工件。
清理它的一个选项(但也增加了更多复杂性)是将源代码和工件下载移动到模板中,然后您可以在每个作业开始时引用它。
main.yaml
stages:
- stage: WPF
jobs:
- job: 'GetVersions'
steps:
- template: "source-and-artifact.yaml"
- task: PowerShell@2
displayName: 'Get Exe Versions'
inputs:
targetType: 'inline'
script: | # Get Versions in powershell
- job: InstallerJob1
dependsOn: 'GetVersions'
steps:
- template: "source-and-artifact.yaml"
source-and-artifact.yaml
steps:
- checkout: none
clean: true
- download: 'repoCi'
artifact: 'WPF'