How to push to repository under SSH protocol using Script task
Platform Notice: Server and Data Center Only - This article only applies to Atlassian products on the server and data center platforms.
The following instructions only work with SSH keys with no passphrase defined.
Scripting and SSH configurations are unsupported and the support for the same is not guaranteed.
Purpose
Set up Bamboo to be able to push source code to your repository using the SSH protocol (from the Bamboo server or a Bamboo remote agent).
Solution
1. Editing "hosts" file and setting up SSH
2. Set up Script task
In Bamboo, add a Script task to your existing Job after the Source Code Checkout task:
echo "# =================== #"
echo "# git remote set-url origin"
echo "# =================== #"
git remote set-url origin "ssh://stash.repository:7999/bam/ssh.git"
echo "# =================== #"
echo "# git config -l"
echo "# =================== #"
git config -l
echo "# =================== #"
echo "# git config user"
echo "# =================== #"
git config --local user.name root
git config --local user.email root@localhost
echo "# =================== #"
echo "# create file"
echo "# =================== #"
echo "${bamboo.planKey}-${bamboo.buildNumber}" >> file.txt
echo "# =================== #"
echo "# git add file.txt"
echo "# =================== #"
git add file.txt
echo "# =================== #"
echo "# git commit"
echo "# =================== #"
git commit -m "add ${bamboo.planKey}-${bamboo.buildNumber}"
echo "# =================== #"
echo "# git push origin master"
echo "# =================== #"
git push origin master
Test
Run a new build and you should find the following in the build logs:
simple 29-May-2015 16:34:27 Starting task 'git push - no passphrase' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
command 29-May-2015 16:34:27 Beginning to execute external process for build 'Repositories - Git (Stash) - Default Job #2 (REP-GS-JOB1-2)'\n ... running command line: \n/bin/sh /tmp/REP-GS-JOB1-2-ScriptBuildTask-1848464132733721778.sh\n ... in: /<bamboo-home>/xml-data/build-dir/REP-GS-JOB1\n ... using extra environment variables:
...
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # git remote set-url origin
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # git config -l
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 core.repositoryformatversion=0
build 29-May-2015 16:34:27 core.filemode=true
build 29-May-2015 16:34:27 core.bare=false
build 29-May-2015 16:34:27 core.logallrefupdates=true
build 29-May-2015 16:34:27 remote.origin.url=ssh://stash.repository:7999/bam/ssh.git
build 29-May-2015 16:34:27 remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # git config user
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # create file
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # git add file.txt
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # git commit
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 [master dfcbee9] add REP-GS-2
build 29-May-2015 16:34:27 1 file changed, 1 insertion(+)
build 29-May-2015 16:34:27 # =================== #
build 29-May-2015 16:34:27 # git push origin master
build 29-May-2015 16:34:27 # =================== #
error 29-May-2015 16:34:27 To ssh://stash.repository:7999/bam/ssh.git
error 29-May-2015 16:34:27 99e9848..dfcbee9 master -> master
simple 29-May-2015 16:34:27 Finished task 'git push - no passphrase' with result: Success