我正在尝试在 GitLab CI 中设置构建过程。 现在我正在使用带有 Powershell 的 Windows 运行器,我希望构建过程自动使用构建的版本号标记提交。
这样做的主要原因是为了在 Gitlab wiki 中启用自动更改日志生成,不要与通常放在实际项目存储库中的 changelog.md 混淆。
我已经尝试从 Powershell 脚本中推送标签,但是推送永远不会完成并且会无限循环,我不清楚为什么会发生这种情况。
脚本调用以下命令
[System.Console]::WriteLine("Tagging git commit (${env:CI_BUILD_REF} ) with tag (v$Version)");
$gitProcess = Start-Process -FilePath "git" -NoNewWindow -Wait -PassThru -ArgumentList "tag -a v$Version ${env:CI_BUILD_REF} -m ${env:CI_BUILD_REF_NAME}_$Version"
if($gitProcess.ExitCode -ne 0)
{
[System.Console]::WriteLine("Git failed to tag the current build");
exit $gitProcess.ExitCode
}
[System.Console]::WriteLine("Pushing tag");
$gitProcess = Start-Process -FilePath "git" -NoNewWindow -Wait -PassThru -ArgumentList "push origin v$Version"
if($gitProcess.ExitCode -ne 0)
{
[System.Console]::WriteLine("Git could not push tags to GitLab");
exit $gitProcess.ExitCode
}
这是这些行的输出:
Tagging git commit (9b2feb10340c9f8c86ce7c29460e0bfc5dba6f31 ) with tag (v4.1.295.2274)
Pushing tag
进程就卡在这里,标签永远不会推送或显示在存储库中。
为清楚起见,这是批处理等效项:
git tag -a v%Version% %CI_BUILD_REF% git push origin v%Version%
最佳答案
这里的问题只是权限问题。 Gitlab Windows Runner 没有推送权限,只有获取/克隆权限。 为了解决这个问题,我添加了一个 Remote 作为脚本的一部分,它具有针对此特定任务的用户设置。
凭据是从 secret 文件加载的,并且build设置为在每次构建时克隆存储库。
关于git - 在 Gitlab CI Auto-Tag commit on build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40493286/