【发布时间】:2020-12-01 18:21:24
【问题描述】:
我是天蓝色管道的新手。我已经使用 azure 管道构建作业,并且源代码在同一个分支 dev 中并且运行良好,但是是否可以在不同的分支中拥有 azure 管道和源代码?
如果是这样,请帮助我
另外,如何在 azure 管道中实现分支参数化作业?
【问题讨论】:
标签: azure azure-devops azure-pipelines
我是天蓝色管道的新手。我已经使用 azure 管道构建作业,并且源代码在同一个分支 dev 中并且运行良好,但是是否可以在不同的分支中拥有 azure 管道和源代码?
如果是这样,请帮助我
另外,如何在 azure 管道中实现分支参数化作业?
【问题讨论】:
标签: azure azure-devops azure-pipelines
感谢您对此的快速回复 来自不同仓库的结帐代码运行良好 但是关于参数化分支名称 我使用了以下但没有工作
例子
- name: branch
displayName: Branch Name
type: string
default: dev
values:
- dev
- test
resources:
repositories:
- repository: project
type: git
name: project
ref: ${{ parameters.branch }}
【讨论】:
不,这不是必需的。当您为现有文件定义管道时,您可以选择一个分支:
您甚至可以将管道定义放在不同的存储库中,并从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
编辑:
就这个问题而言:
另外,如何在 azure 管道中实现分支参数化作业?
这是可能的,但不使用内置功能来获取存储库。您需要的是使用例如 powershell 任务和此命令:
GIT clone -b <branch> https://<PAT>@dev.azure.com/Organization/My%20Project/_git/MyRepo
请同时输入您的 YAML checkout: none,因为我们不想通过 standard pipeline task 获取源代码。
在上述命令中,您必须输入 PAT 令牌。更多关于这方面的信息你会发现here
【讨论】: