具有多个工件的AzureDevOps发布管道 [英] AzureDevOps Release pipeline with multiple artifacts
问题描述
是否可能有一个包含多个工件的发布管道,这些工件会有条件地触发各个阶段.
Is it possible to have a single release pipeline with multiple artifacts that will trigger separate stages conditionally.
示例:
(构建工件1)
构建 Web
(构建工件2)
构建 Identity
设置发布管道时,我会创建一个管道并添加
When i setup my release pipeline I create one pipeline and add the
(构建工件1)
-> Web阶段
(构建工件2)
-> Identity Stage
会自动触发发布,并将其设置为发布后
both of those artifacts are set trigger a release automatically and set to After Release
我遇到的问题是,当我为(Build Artifact 2)
的构建排队时,两个阶段都将部署.而且我只希望部署 Identity Stage
,反之亦然.
The problem I have is that when I queue the build for (Build Artifact 2)
both stages will deploy. And i only want Identity Stage
to deploy and visa versa.
我希望所有内容都在一个管道中的原因是,因为我所有的工件都包含在一个管道中,我知道如果创建单独的管道,我可以做到这一点.
The reason i want everything in one pipeline is because then all my artifacts is contained in one pipeline, I know i can do this if i create separate pipelines.
推荐答案
更多地考虑您的情况,让第三个工件生成CI(在构建完成时触发)会更干净(请阅读:没有失败的阶段).其他2个CI版本.该中介构建将根据触发原因进行标记(即 Web
或 Identity
).此构建的工件将是对上游工件的重新打包(使用下载工件任务),从而使您的发布管道可以使用一个可能具有2个不同标记值的工件.这使您在预释放条件下的伪影过滤器有更多的牙齿.
Thinking more about your situation, it might be cleaner (read: no failing stages) to have a third artifact producing CI that is triggered on the build completion of the other 2 CI builds. That mediation build would get tagged according to why it was triggered (ie. Web
or Identity
). The artifact of this build would be a re-packaging of the upstream artifact (use the download artifact task), allowing your release pipeline to consume one artifact that might have 2 different tag values. This gives your artifact filters in pre-release conditions more teeth.
Web_CI
\ #Web - - Web Development - - Web Production
- -\ /
> = WebIdSwitch_CI - - <
- -/ \
/ #Id - - Id Development - - Id Production
Id_CI
原始答案
对此我可能是错的,但是我认为您需要根据 RELEASE_TRIGGERINGARTIFACT_ALIAS
中的值来运行阶段.
I could be wrong about this, but I think you're going to need to have the stages run based on the value in RELEASE_TRIGGERINGARTIFACT_ALIAS
.
可能有几种方法可以做到这一点,例如
There might be a couple ways to do this, such as
- 在每个工件发布后都有一个缓冲阶段,如果值不正确(让您的工作阶段在其缓冲之后执行),则让它们失败.
- 使用新的第一个任务来签入作业,并失败
- 在每个任务上写一个条件执行选项,以确保在触发工件不正确的情况下,它们都不执行
可以使用 $(Release.TriggeringArtifact.Alias)
在管道上访问变量,也可以使用 $ env:RELEASE_TRIGGERINGARTIFACT_ALIAS
在powershell中访问变量.
The variable can be accessed on the pipeline using $(Release.TriggeringArtifact.Alias)
or in powershell with $env:RELEASE_TRIGGERINGARTIFACT_ALIAS
.
我不确定您是否已经在部署前的条件中在舞台上使用了Artifact筛选器,但这可能是另一种方式,并不是那么简单.我必须将一个测试管道放在一起,然后尝试一下.
I'm not sure if you're using Artifact Filters on your stages already as part of your pre-deployment conditions, but that may be another way that isn't as much of a hack. I'll have to put a test pipeline together and try it out.
这篇关于具有多个工件的AzureDevOps发布管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!