2016-11-08 20 views
2

我试图在GitLab CI中设置构建过程。 现在我正在使用Powershell的Windows runner,并且我希望构建过程能够自动标记提交版本号。在Gitlab CI自动标记提交构建

这样做的主要原因是在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的标签-a v%的版本%%CI_BUILD_REF% 混帐推起源v%的版本%

+0

你用$ env:CI_BUILD_REF试过了吗?我不认为你正在使用env变量。你不需要做$()来使用env变量。所以没有{} – 4c74356b41

+0

这些行似乎工作正常,我会将输出添加到职位 –

+0

您是否尝试过从cmd执行此操作?它工作吗? – 4c74356b41

回答

2

这里的问题是一个简单的权限问题。 Gitlab Windows Runner没有推送权限,只能获取/克隆。 为了弥补这一点,我添加了一个远程作为脚本的一部分,该脚本具有用于该特定任务的用户设置。

凭证从秘密文件中加载,并且构建版本用于克隆每个构建的存储库。