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

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

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.

*Fisheye および Crucible は除く

要約

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.

ソリューション

  • 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:

echo "# ================= #"
echo "# git checkout"

GIT_SSH_COMMAND='ssh -i /Users/john/.ssh/private_key_file -o IdentitiesOnly=yes' git clone git@bitbucket.org:john/bitbucketstationlocations.git
echo "Checkout to the location" ${bamboo.build.working.directory}
1s -lart ${bamboo.build.working.directory}
cd bitbucketstationlocations
git checkout develop
git status

echo "# ================= #"
Sample ~/.ssh/config file
Host gitserv
    Hostname remote.server.com
    IdentityFile ~/.ssh/id_rsa.bitbucket
    IdentitiesOnly yes
Example build log output from Script Task
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

最終更新日 2022 年 6 月 15 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.