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

How to automatically 'git tag -a' after a pull request has completed on Azure Devops?

拉取请求 (PR) 完成后,我们如何在 master 上添加自定义注释标签,自动

更多背景:

仅在 MAJOR 上固定示例:

resources:
  repositories:
    - repository: templates
      type: git
      name: template_devops_pipelines
      ref: "refs/tags/v1"

我使用的示例标记管道:

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'])

你基本上需要三样东西:

  1. 使用 persistCredentials 结帐 - 这样您的管道可以稍后标记和推送
  2. 配置gituser.email和user.password
  3. 标签&推送

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