How to push a repository tag for a specific commit from Bamboo to a remote repository

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Repository Tag task in Bamboo will tag the most recent revision in a remote repository. So it's not possible to tag a specific commit using this task. This document explains how to push a repository tag for a specific commit from Bamboo to a remote repository via a script task.

Environment

All supported versions of Bamboo

Solution

  • Ensure you have a Git executable installed on the remote agent server
  • Ensure that the user running the remote agent process has access to the executable that is accessible on the $PATH

  • Upload your SSH keys for authentication directly to the remote agent server. This is necessary because the Bamboo server caches a remote copy of your Git repository and when checkouts are performed they are against the Bamboo server. With the checkout task credentials available to Bamboo are present for the task. With script tasks, there is no access to keys stored against the Bamboo server
  • Configure the script task to utilize the keys local to the remote agent either by using the environment variable GIT_SSH_COMMAND or defining it in your ~/.ssh/config using the IdentityFile directive
  • By using a script task in Bamboo, the repository tag can be pushed to a remote repository (below is tested with the Bitbucket Server Repo). Below is the sample script task:

    echo "# =================== #"
    echo "# git remote set-url origin"
    echo "# =================== #"
    git remote set-url origin "<provide_your_repository_server_ssh_url>"
    
    echo "# =================== #"
    echo "# Define and echo Tag"
    echo "# =================== #"
    tagid=${bamboo.planKey}-${bamboo.buildNumber}
    echo $tagid
    
    echo "# =================== #"
    echo "# git tag"
    echo "# =================== #"
    git tag -a $tagid <commit_id> -m "tagged through Bamboo"
    
    echo "# =================== #"
    echo "# git push origin tag"
    echo "# =================== #"
    git push origin $tagid

(info) Replace <provide_your_repository_server_ssh_url> with your repository server ssh URL
(info) Replace <commit_id> with your repository commit_id you want to tag
(info) In above code, tag id is defined with parameter ${bamboo.planKey}-${bamboo.buildNumber}

  • SAMPLE ~/.SSH/CONFIG FILE:

    Host gitserv
        Hostname remote.server.com
        IdentityFile ~/.ssh/id_rsa.bitbucket
        IdentitiesOnly yes


Last modified on Jan 10, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.