How to perform a Git SSH checkout from a Bamboo Script Task

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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

Some use cases require git operations to be performed via scripts and not the Source-code checkout task and special considerations need to be taken to ensure proper connection.

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 and 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

Sample script task:

  • Task description: SSH GIT Checkout

  • Interpreter: Shell

  • Script location: Inline

Sample ~/.ssh/config file

1 2 3 4 Host gitserv Hostname remote.server.com IdentityFile ~/.ssh/id_rsa.bitbucket IdentitiesOnly yes

Example build log output from Script Task

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 03-May-2022 17:07:00 Starting task 'SSH GIT Checkout' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script' command 03-May-2022 17:07:00 Beginning to execute external process for build 'pRO - SSHGitPLan - Default Job #7 (PRO-SSHGITPLAN-JOB1-7)'\n ... running command line: \n/Users/john/dev/MSB/bamboo-home/BAM_AG_8.1.5/temp/PRO-SSHGITPLAN-JOB1-7-ScriptBuildTask-5792526802923535794.sh\n ... in: /Users/john/dev/MSB/bamboo-home/BAM_AG_8.1.5/xml-data/build-dir/PRO-SSHGITPLAN-JOB1\n build 03-May-2022 17:07:00 # =================== # build 03-May-2022 17:07:00 # git checkout error 03-May-2022 17:07:00 Cloning into 'bitbucketstationlocations'... build 03-May-2022 17:07:05 Checkout to the location /Users/john/dev/MSB/bamboo-home/BAM_AG_8.1.5/xml-data/build-dir/PRO-SSHGITPLAN-JOB1 build 03-May-2022 17:07:05 total 0 build 03-May-2022 17:07:05 drwxr-xr-x 5 john staff 160 3 May 17:06 .. build 03-May-2022 17:07:05 drwxr-xr-x 3 john staff 96 3 May 17:07 . build 03-May-2022 17:07:05 drwxr-xr-x 9 john staff 288 3 May 17:07 bitbucketstationlocations error 03-May-2022 17:07:05 Switched to a new branch 'develop' build 03-May-2022 17:07:05 Branch 'develop' set up to track remote branch 'develop' from 'origin'. build 03-May-2022 17:07:05 On branch develop build 03-May-2022 17:07:05 Your branch is up to date with 'origin/develop'. build 03-May-2022 17:07:05 build 03-May-2022 17:07:05 nothing to commit, working tree clean build 03-May-2022 17:07:05 # =================== # simple 03-May-2022 17:07:05 Finished task 'SSH GIT Checkout' with result: Success

Updated on March 12, 2025

Still need help?

The Atlassian Community is here for you.