如何设置Az DevOps管道以驻留在其他分支中? [英] How to setup my Az DevOps pipeline to live in a different branch?

查看:63
本文介绍了如何设置Az DevOps管道以驻留在其他分支中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为.NET Core 3.0 mvc项目的CI设置Azure DevOps管道.

I'm setting up Azure DevOps pipeline for CI for a .NET Core 3.0 mvc project.

我创建了一个新分支 DEVOPS ,我希望将其存储在YAML文件中.该文件包含一个触发,用于更改 master 分支:

I've created a new branch, DEVOPS, that I would like to store the YAML file in. The file includes a trigger for changes to the master branch:

触发:
-大师

trigger:
- master

池:
vmImage:'ubuntu-latest'

pool:
vmImage: 'ubuntu-latest'

下面还有#个其他步骤/任务...

# other steps/tasks below...

我从 DEVOPS 分支中删除了除 .gitignore azure-pipelines.yml 以外的所有文件,将其提交并推送到源(Az DevOps回购).

I deleted all files except .gitignore and azure-pipelines.yml from the DEVOPS branch, committed it, and pushed it to origin (Az DevOps Repo).

然后我切换到 master 分支,删除 azure-pipelines.yml 文件,提交并推送.

I then switched to the master branch, deleted the azure-pipelines.yml file, committed, and pushed.

这没有触发管道

this did not trigger the pipeline

然后,我对主视图,提交视图和推送视图中的其中一种视图进行了更改.

Then I made a change to one of the views in master, committed, and pushed.

这也没有触发管道

this also did not trigger the pipeline

因此,如何配置Azure DevOps Pipelines将 azure-pipelines.yml 文件存储在 master 以外的分支中,并触发对的更改掌握?

So, how can I configure Azure DevOps Pipelines to store the azure-pipelines.yml file in a branch other than master, and trigger on changes to master?

推荐答案

根据您的操作步骤和YAML配置,无法触发构建是合理的.

According to your operation steps and the YAML configuration, the build could not be triggered is reasonable.

让我们首先关注YAML配置.在YAML定义中,将 master 设置为触发器分支.这意味着只有在 master 上发生的更改才能触发此构建管道.

Let's focus on the YAML configuration first. In you YAML definition, you set master as trigger branch. This means only changes occurred on master can trigger this build pipeline.

在第一步中,您从 DEVOPS 分支中删除了一些文件.然后提交并推送到 remotes/Origin 中.但是,正如您在管道中定义的那样,此操作无法触发该管道.符合预期.

In your first action, you delete some files from DEVOPS branch. Then commit and push it into remotes/Origin. But, as what you defined in pipeline, this action could not trigger this pipeline. This is as expect.

接下来,在 master 分支中,删除 azure-pipelines.yml 文件,然后提交并推送.请注意,此时,远程主分支已与本地主分支同步.一言以蔽之,在您推送到原始位置之后,Azure Devops的主分支中没有任何 azure-pipelines.yml 文件.

Next, in master branch, you delete the azure-pipelines.yml file, then commit and push it. Note, at this time, the remote master branch has been sync with the local master branch. In one word, after you push to origin, no azure-pipelines.yml file exists in the master branch of Azure Devops.

,是否可以运行该构建取决于yml是否存在.是的,您已经在master分支上进行了一些更改.但是如果没有 yml 文件,该构建将无法成功运行.这就是为什么您遇到未触发管道的原因.

BUT, whether the build can run depends on whether yml exists or not. Yeah, you have made some changes on master branch. But without yml file, the build could not be ran successfully. That's why you encountered the pipeline did not be triggered.

而且,您要执行下一个操作的原因也是相同的.

And, same reason for your next action.

如何配置Azure DevOps管道以存储除master以外的其他分支中的azure-pipelines.yml文件,并在更改为主人?

How can I configure Azure DevOps Pipelines to store the azure-pipelines.yml file in a branch other than master, and trigger on changes to master?

到目前为止,如果您的构建定义类型为 YAML ,则无法实现.

Until now, this could not be achieve if what's your build definition type is YAML.

对于定义类型为YAML的管道,要达到您的期望,具有相同配置的 yml 文件也必须存储在管道中定义的相关分支中.

For the pipeline which definition type is YAML, to achieve what you expect, the yml file with the same configuration must also stored in the relevant branches which be defined in the pipeline.

以您在问题中描述的示例为例.如果仅将 yml 文件存储在 DEVOPS 分支中,则无论在 master 分支上进行任何更改,都不会触发构建.

Take the example you described in the question. If you only store the yml file in DEVOPS branch, no matter do any changes on master branch, it will never trigger the build.

要触发对master的更改,此 yml 文件也必须存储在master分支中.因此,可以触发定义类型为YAML的构建管道的前提是,如果yml定义中列出了yml文件,则它也必须存在于相关分支中.这是因为,此构建类型可以基于源文件中的 yml 运行.

To achieve trigger on changes to master, this yml file must also stored in master branch. So, the pre-condition of build pipeline which definition type is YAML can be triggered is, the yml file must also exists in the relevant branches if it is listed in the yml definition. This because, this build type can run based on the yml from source files.

这篇关于如何设置Az DevOps管道以驻留在其他分支中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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