How to setup my Az DevOps pipeline to live in a different branch?

最后都变了- 提交于 2021-02-11 14:22:44

问题


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

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

pool:
vmImage: 'ubuntu-latest'

# other steps/tasks below...

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

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

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?


回答1:


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

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.

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.

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.

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.


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?

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

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.

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.

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.



来源:https://stackoverflow.com/questions/58295503/how-to-setup-my-az-devops-pipeline-to-live-in-a-different-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!