在 Azure Devops 管道中:推送标签有效,但不推送

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

我不明白有关 Git 身份验证在 Azure Devops Yaml 管道中的工作原理。

我做什么

我运行这条管道:

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"

它本质上是 运行 这个位于 Tuto-Deploy 中的 PowerShell 脚本:

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'

我有什么

git 推送标签工作正常。 但是 git 推送引发了几条与身份验证问题相关的错误消息:

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:

其他信息

我向我的构建代理授予了创建标签贡献者权限。

我想知道的

为什么添加、提交和推送有认证问题,但推送标签没有?为什么推送标签需要persistCredential,但对提交和推送没有影响?

谢谢

这不完全是身份验证问题 - persistCredentials 会处理这个问题。但是为了提交更改,git 必须为新提交分配一个作者。为此,它需要 name/email 对。

您只需执行错误信息中的命令即可:

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

在脚本和错误消失之前,将它们添加到您的脚本中或 运行 它们作为单独的管道步骤。