我是 azure 管道的新手。我有使用 azure 管道的构建作业,源代码位于同一分支开发中并且运行良好,但是是否可以在单独的分支中拥有 azure 管道和源代码?
如果是这样,请帮助我
此外,我如何在 azure 管道中实现分支参数化作业?
最佳答案
不,这没有必要。当您为现有文件定义管道时,您可以选择一个分支:
您甚至可以将管道定义放在不同的存储库中并从 multiple repo pipeline 中受益来实现这个目标。
如果你想参数化管道,你应该看看 templates :
# File: templates/npm-with-params.yml
parameters:
- name: name # defaults for any parameters that aren't specified
default: ''
- name: vmImage
default: ''
jobs:
- job: ${{ parameters.name }}
pool:
vmImage: ${{ parameters.vmImage }}
steps:
- script: npm install
- script: npm test
然后你可以这样使用它:
# File: azure-pipelines.yml
jobs:
- template: templates/npm-with-params.yml # Template reference
parameters:
name: Linux
vmImage: 'ubuntu-16.04'
- template: templates/npm-with-params.yml # Template reference
parameters:
name: macOS
vmImage: 'macOS-10.14'
- template: templates/npm-with-params.yml # Template reference
parameters:
name: Windows
vmImage: 'vs2017-win2016'
您还可以使用来自不同存储库的模板。假设您在 Contoso/BuildTemplates 存储库中有 common.yml 模板:
# Repo: Contoso/LinuxProduct
# File: azure-pipelines.yml
resources:
repositories:
- repository: templates
type: github
name: Contoso/BuildTemplates
jobs:
- template: common.yml@templates # Template reference
编辑:
就这个问题而言:
Additionally how can i achieve branch parameterized job in azure pipelines?
这是可能的,但不使用内置功能来获取存储库。您需要使用例如 powershell 任务和此命令:
GIT clone -b <branch> https://<PAT>@dev.azure.com/Organization/My%20Project/_git/MyRepo
请同时输入您的 YAML checkout: none
因为我们不想通过 standard pipeline task 获取源代码.
在上面的命令中,您必须输入 PAT token 。有关此的更多信息,您会发现 here
关于Azure管道: is it mandatory to have azure pipelines and code in same branch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63369113/