【问题标题】:Azure DevOps repos not tagging right tags using git commandsAzure DevOps 存储库未使用 git 命令标记正确的标签
【发布时间】:2021-05-13 23:22:45
【问题描述】:

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

我在标记 repos 时遇到了一些问题 -

  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 中?

【问题讨论】:

    标签: git azure-devops azure-repos


    【解决方案1】:

    PushTags 中的命令在本地存储库中执行,并且似乎从未更改存储库。更改 origin 的推送 url 只会更新到远程仓库的推送路由,本地仓库仍然是原来的。当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 并不熟悉。你可以参考它的文档。

    【讨论】:

    • 谢谢。我用 azure devops api 替换了 git 命令,这对我有用。
    猜你喜欢
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多