允许PR构建验证构建而无需发布工件 [英] Allow PR Build Validation builds without publishing artifacts

查看:81
本文介绍了允许PR构建验证构建而无需发布工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我们的master分支上为PR建立一些构建验证(我们正在使用Git和VSTS).我添加了一些构建策略,以根据更改的文件开始各种构建.在某些背景下,我们会在流程的早期阶段创建PR,以便在开发功能分支时可以跟踪更改并添加注释.

I'm trying to set up some build validation for PR's on our master branch (We're using Git and VSTS). I added some build policies to kick off various builds depending on what files have changed. For some background, we create PR's somewhat early in the process so we can track changes and add comments as our feature branch is developed.

现在,我希望这些构建能够运行并成功完成PR,但是,我不想发布这些构建的输出(工件).我们的发布着眼于要部署的最新构建工件,在这种情况下,最新构建工件将来自PR.如果我们确实允许发布PR中的这些构建工件,那么我们会将功能分支代码(来自PR)发布到我们的主站点,这是不希望的(我们有单独的发布来处理功能)分公司).

Now, I want these builds to run and succeed in order for a PR to be completed, however, I don't want the output (artifacts) from these builds to be published. Our publishes look at the latest build artifact to deploy, and in this case, the latest build artifact would be from the PR. If we did allow these build artifacts from the PR to be published, then we'd be publishing feature branch code (which came from the PR) to our main site, which isn't desirable (we have a separate publish to handle our feature branch sites).

本质上,在执行PR时,我只想运行构建以确保所有内容都是洁净的,然后在构建完成后将其丢弃.

Essentially, when doing a PR, I just want to run the build to make sure that everything is kosher, and then throw away the build once it's completed.

除了创建仅用于PR验证的构建定义外,我不确定该怎么做.我已经在Google上搜索并询问了周围,但是我不是在问正确的问题,否则答案就不是我希望的那么简单.

Outside of creating a build definition solely for PR validation, I'm not sure what I can do. I've googled and asked around, but I'm either not asking the right questions, or the answer isn't as simple as I hope.

希望我提供了足够的细节来解释我的问题.

Hopefully I've included enough details to explain my problem.

如何在PR上运行构建验证,而无需发布并部署由验证构建产生的构建工件?

How can I run build validations on a PR without having a publish pick up and deploy the build artifact that resulted from the validation build?

我尝试为发布任务添加条件(也尝试将发布置于一个阶段并有条件地运行该任务).但是,当我制作一个新版本时,它仍然会看到运行的构建定义.现在,我想像一下,如果我尝试发布该构建定义,它将失败,因为未创建任何构件.但是我什至不想在发布时看到该构建定义(不想意外选择它).

I tried adding conditions to the publish task (also tried putting the publish in a phase and conditionally running that). However, when I go to make a new release, it still sees the build definition that was run. Now, I imagine that if I tried to release that build definition, it would fail because no artifact was created. But I don't even want to see that build definition when I'm doing a release (don't want to accidentally select it).

推荐答案

您可以将发布工件"任务放在自己的构建定义的末尾,然后将运行此阶段"与使用变量表达式的自定义条件"结合使用.您也可以按照以下评论中Dan的建议,在任务"级别执行此操作.

You could put the Publish Artifact task its own Phase at the end of your build definition then use 'Run this phase' with 'Custom condition using variable expressions'. You can also do this at the Task level as Dan suggested in the comment below.

not(eq(variables['Build.Reason'], 'PullRequest'))

https://docs.microsoft.com/zh-cn/vsts/pipelines/process/conditions?view = vsts

这篇关于允许PR构建验证构建而无需发布工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆