Azure DevOps 存储库未使用 git 命令标记正确的标签

Azure DevOps repos not tagging right tags using git commands

我有标记 Azure DevOps 存储库的脚本。

我在标记存储库时遇到了一些问题 -

  1. 如果标签仍然不存在,我会遇到致命问题:标签已经存在,然后脚本继续执行,并且标签 repo

  2. 我在脚本中给出了标签。如果我更改脚本中的标签,它会用 2 个标签标记 repo。脚本中的先前和更新标签

例如这是命令 - git tag -a AzDo -m "{}"".format(details) 如果我将其更改为 git tag -a AzDo_123 -m "{}"".format(details) 和 运行 脚本。它的标签回购有 2 个标签 AzDo_123、Azdo

    def PushTags(org,token,project,repoName,user,email):
      os.system("git config --global user.name \"{}\"".format(user))
      os.system("git config --global user.email \"{}\"".format(email))
      os.system("git remote set-url --push origin https://{User_Name}:
                {PAT}@{Org}.visualstudio.com/{Project_Name}/_git/{Repo_Name}"\
                     
       .format(User_Name=user,PAT=token,Org=org,Project_Name=project,Repo_Name=repoName))
      os.system("git tag -a AzDo -m \"{}\"".format(details))
      os.system("git push --tags")


       

我是否需要在脚本(git 命令)中进行任何更改以确保它只对 repo 标记正确的标签?

PushTags中的命令是在本地存储库中执行的,似乎存储库从未更改过。更改origin的pushurl只是更新到远程仓库的push路由,本地仓库还是原来的。当 PushTags 被多次调用时,它总是尝试在同一个提交(HEAD)上创建相同的标签,所以它抱怨标签已经存在。

我可以想到 2 个解决方案。一种是获取分支,然后在正确的提交上创建标签。另一个是有的话调用Azure的restapi。

假设您要在存储库 repoName.

的分支 foo 上的提交 123abc 上创建标签 AzDo
# fetch foo from repoName
git fetch ${url_to_repoName} foo
# as you run the commands in the same repository, remove the existing AzDo first
git tag -d AzDo
# create tag AzDo on 123abc
git tag -a AzDo -m <msg> 123abc
# push the new Azdo to repoName
git push ${url_to_repoName} refs/tags/Azdo:refs/tags/Azdo

关于 restapi,我对 Azure DevOps 不熟悉。你可以参考它的文档。