在 Azure Devops 上完成拉取请求后如何自动“git tag -a”?

Adr*_*rie 6 azure-devops azure-pipelines azure-pipelines-yaml

我们如何添加自定义注释标记master,一旦引入请求(PR)完成后,会自动

更多背景:

  • 使用 azure-pipelines.yml
  • master强制使用 PR 的分支策略
  • 我们有一个存储 Azure Devops 管道模板的存储库(“devops 模板存储库”)
  • 其他存储库有一个引用“devops 模板”存储库的根管道文件
  • 我们使用 SEMVER 来标记我们的产品,包括 devops 模板存储库
  • 在根管道中,我们希望固定到 devops 模板存储库的 SEMVER 版本
  • 我们目前使用以下每个手动标记以指向 PR 完成后发生的合并提交
    • “V MAJORMINORPATCH
    • “诉MAJORMINOR
    • “v MAJOR

引脚上MAJOR唯一的例子:

resources:
  repositories:
    - repository: templates
      type: git
      name: template_devops_pipelines
      ref: "refs/tags/v1"
Run Code Online (Sandbox Code Playgroud)

qbi*_*bik 8

我使用的示例标记管道:

trigger:
  - main

variables:
  user.email: "devops@myorganization.com" 
  user.name: "DevOps"
  defaultBranch: "main"
  major: 1
  minor: 0
  patch: $[counter(variables['patch'], 2)]

name: $(major).$(minor).$(patch)

steps:
  - checkout: self
    persistCredentials: true
  - script: |
      git config user.email ${{variables['user.email']}}
      git config user.name ${{variables['user.name']}}
    displayName: 'configure git credentials'
  - script: | 
      git tag "$(Build.BuildNumber)"
      git push origin "$(Build.BuildNumber)"
    displayName: 'git tag'
    condition: eq(variables['Build.SourceBranchName'], variables['defaultBranch'])
Run Code Online (Sandbox Code Playgroud)

你基本上需要三件事:

  1. 签出persistCredentials- 这样您的管道可以稍后标记和推送
  2. 配置 git user.email 和 user.password
  3. 标签和推送

对于最后一步,您需要向管道构建服务帐户分配“贡献”权限。转到:Project Settings -> Repositiories -> {your repo} -> Security,找到用户{your organization} Build Service并将贡献设置为Allow