如何解决在 Azure Devops 管道中:推送标签有效,但不推送
我不明白 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 push 标签工作正常。 但是 git push 引发了一些与身份验证问题相关的错误消息:
作者身份不明
*** 请告诉我你是谁。
运行
git config --global user.email "you@example.com"
git config --global user.name "你的名字"
设置您帐户的默认身份。省略 --global 设置 身份仅在此存储库中。
致命:无法自动检测电子邮件地址(得到 'VssAdministrator@WIN-QB09EGE8K8T.(none)') 致命:你不是 目前在一个分支上。将历史推向当前 (分离头)状态现在,使用
git push origin HEAD:
其他信息
我向我的构建代理授予了创建标签和贡献者权限。
我想知道的
为什么添加、提交和推送有身份验证问题,但没有推送标签?为什么 persistCredential 是推送标签所必需的,但对提交和推送没有影响?
谢谢
解决方法
这不完全是身份验证问题 - persistCredentials
会处理这个问题。但是为了提交更改,git 必须为新提交分配一个作者。为此,它需要一个姓名/电子邮件对。
您只需要执行错误消息中的命令:
git config --global user.email "pipeline@example.com"
git config --global user.name "pipeline"
在脚本和错误消失之前,要么将它们添加到您的脚本中,要么将它们作为单独的管道步骤运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。