Fré*_*uze 1 git azure-devops azure-pipelines
我不明白有关 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"
Run Code Online (Sandbox Code Playgroud)
它本质上运行位于 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'
Run Code Online (Sandbox Code Playgroud)
我拥有的
git push 标签工作正常。但 git Push 引发了一些与身份验证问题相关的错误消息:
作者身份不明
*** 请告诉我你是谁。
跑步
git config --global user.email "you@example.com"
git config --global user.name "你的名字"设置您帐户的默认身份。省略 --global 仅在此存储库中设置标识。
致命:无法自动检测电子邮件地址(得到“VssAdministrator@WIN-QB09EGE8K8T。(无)”)致命:您当前不在分支上。要立即推送导致当前(分离的 HEAD)状态的历史记录,请使用
git Push 原点头:
其他信息
我向我的构建代理授予了“创建标签”和“贡献者”权限。
我想知道什么
为什么add、commit、push有认证问题,而push标签没有?为什么推送标签需要persistCredential ,但对commit和push没有影响?
谢谢
这不完全是身份验证问题 - persistCredentials解决这个问题。但为了提交更改,git 必须为新提交分配一个作者。为此,它需要姓名/电子邮件对。
您只需执行错误消息中的命令即可:
git config --global user.email "pipeline@example.com"
git config --global user.name "pipeline"
Run Code Online (Sandbox Code Playgroud)
在脚本和错误消失之前,将它们添加到脚本中或将它们作为单独的管道步骤运行。
| 归档时间: |
|
| 查看次数: |
1824 次 |
| 最近记录: |