gitazure-devopsgit-tag

Pushing Tags in Azure Devops Via Powershell Commands Doesn't Set Tagger Information


Hi I have a release that automatically tags the release commit in the source repo via some git commands in a powershell script. Its below:

cd $(Agent.ReleaseDirectory)\_repo_root
git checkout $(Build.SourceVersion)
git tag $(RELEASE_TAG)
git push --tags

Write-Host tagged $(RELEASE_TAG) on commit $(Build.SourceVersion)

It does correctly tag the release commit, however in the ADO tags ui it doesn't show any tagger information: enter image description here

4.1.0 was added manually through the ADO dialog but the releases > 4.2 were created through the script above. Is there a way to provide this information to ADO from a script in a release pipeline?


Solution

  • I can reproduce the same with your code in release pipeline:

    enter image description here

    This is because Lightweight tags are displayed with a tag name and commit, only Annotated tags are displayed with a tag name, message, commit, tagger, and creation date(doc link).

    enter image description here

    Please add comment when you add tag: git tag $(RELEASE_TAG) -m "test tag".

    In addition, you are using Scoped build identities whose token is $(system.accesstoken) to push the tag to the repo, the identity doesn’t include personal information like name or email. You need to add the user info with git config command.

    The code below works:

    cd "$(Agent.ReleaseDirectory)\_repo_root"
    git checkout $(Build.SourceVersion)
    git config --global user.name "testuser"            # add user info and email
    git config --global user.email "your.email@example.com"
    git tag $(RELEASE_TAG) -m "test tag"                # add comment for tag
    git push --tags
    Write-Host tagged $(RELEASE_TAG) on commit $(Build.SourceVersion)
    

    It has the tagger info as below:

    enter image description here

    enter image description here

    Add more :

    In release pipeline, tick the option Allow scripts to access the OAuth token to allow the git command to use the scoped build identity.

    enter image description here

    There are two type scoped build identities as mentioned in above link, my sample below for your reference. On project setting, confirm the identity, it's project-scoped build identity({Project Name} Build Service ({Org Name})) on my side.

    enter image description here

    On target repo which you would add tag, grant the permission for the identity.

    enter image description here