In Gitlab CI Auto-Tag commit on build

SomeInternetGuy

I'm trying to setup a build process in GitLab CI. Right now I'm using a Windows runner with Powershell, and I would like the build process to automatically tag the commit with the version number of the build.

The primary reason for this is to enable automatic change log generation in the Gitlab wiki, not to be confused with the changelog.md that is generally put in the actual project repository.

I've tried pushing the tag from the Powershell script, however the push never completes and cycles endlessly, and it's not clear to me why this happens.

The script calls the following commands

[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
}

Here is the output from these lines:

Tagging git commit (9b2feb10340c9f8c86ce7c29460e0bfc5dba6f31 ) with tag (v4.1.295.2274)

Pushing tag

The process just hangs here, and the tag never pushes or shows up in the repository.

For clarity, this is the batch equivalent:

git tag -a v%Version% %CI_BUILD_REF% git push origin v%Version%

SomeInternetGuy

The issue here was simply a permissions issue. The Gitlab Windows Runner doesn't have permission to push, only fetch/clone. To remedy this, I add a remote as part of the script which has a user setup for this particular task.

The credentials are loaded from a secrets file and the build is setup to clone the repository each build.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related