In an Azure Devops pipeline: push tag works, but not push

Viewed 848

I don't understand a point concerning how Git uthentication works in an Azure Devops Yaml pipeline.

What I do

I run this pipeline :

resources:   repositories:
    - repository: TutoDeployin Tuto-DeployBuild repository
      ref: main
      type: git
      name: Tuto-Deploy

jobs:  
- job: Build

  steps:
    - checkout: self
      clean: true
      persistCredentials: true
    - checkout: TutoDeploy
      clean: true
      persistCredentials: true

    - task: Powershell@2
      inputs:
        pwsh: true
        filePath: '.\tuto-deploybuild\CI\build.ps1'
        arguments: "-repositoryName tuto-deploy"

It essentially run this PowerShell script located in Tuto-Deploy:

Param(
    $repositoryName
)

cd "$($env:Build_SourcesDirectory)/$repositoryName"


$version = @{
    numero = 0
    date = Get-Date
}

$path = "$env:Build_SourcesDirectory" + "/$repositoryName/version"
$versionFile = "$path/version.json"
New-Item -Path $path -ItemType Directory -force


If ((Test-Path $versionFile) -eq $True) {
    $version = ConvertFrom-Json $versionFile -asHashtable
}

$version.numero++

If(!(test-path $path))
{
      New-Item -ItemType Directory -Force -Path $path
}

ConvertTo-Json $version > $versionFile

git tag $version.numero --force
git push --tags --force

git add *
git commit -m 'New version'

What I have

git push tag works fine. But git push raised several error messages related to an authentication issue:

Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'VssAdministrator@WIN-QB09EGE8K8T.(none)') fatal: You are not currently on a branch. To push the history leading to the current (detached HEAD) state now, use

git push origin HEAD:

Other infos

I gave Create tag and Contributor permissions to my build agent.

What I want to know

Why add,commit and push have authentication issue but not push tag? Why persistCredential is necessary for pushing tags but has no impact to commit and push?

Thanks

1 Answers

It's not exactly authentication issue - persistCredentials takes care of that. But in order to commit changes, git has to assign an author to the new commit. For that, it requires a name/email pair.

You just need to execute the commands from the error message:

git config --global user.email "pipeline@example.com"
git config --global user.name "pipeline"

Either add them to your script or run them as a separate pipeline step, before the script and the error should go away.

Related