Azure管道:是否必须在同一分支中使用Azure管道和代码

问题描述

我是天蓝色管道的新手。我已经用azure管道构建了工作,并且源代码在同一个分支dev中并且运行良好,但是有可能在单独的分支中拥有azure管道和源代码吗?

如果是这样,请在此方面帮助我

另外,我如何在Azure管道中实现分支参数化的工作?

解决方法

否,这不是必需的。为现有文件定义管道时,可以选择一个分支:

enter image description here

您甚至可以将管道定义放入另一个回购中,并受益于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

也请checkout: none放入您的YAML,因为我们不想通过standard pipeline task获取源代码。

在上面的命令中,您必须放置PAT令牌。有关此内容的更多信息,您会发现here

,

谢谢您对此的快速回复 来自不同仓库的结帐代码工作正常 但是关于参数化分支名称 我使用了以下内容,但没有用

示例

- name: branch
  displayName: Branch Name
  type: string
  default: dev
  values:
   - dev
   - test

resources:
  repositories:
  - repository: project
    type: git
    name: project
    ref: ${{ parameters.branch }}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...