How to use Bamboo Password Variable to SSH with 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
The below code only works on Linux/Mac OS based system.
This document is focused on how to utilize Bamboo password variables to SSH into remote host using Bamboo Script task.
Solution
Follow the steps to configure the script task:
Add a script task to your Bamboo plan and use the below code:
1 2 3 4 5
#!/usr/bin/expect -f spawn ssh <username>@<hostname> "sh test.txt" expect "Password:" send "${bamboo.password_variable_name}\r" interact
Pointers:
Replace <username> with a username and <hostname> with a hostname of the machine to which you will be establishing the connection.
"sh test.txt" could be changed to commands as well. For example - "echo hello". In this case, this "test.txt" file is present under the home directory of the host in which I am logging into using the SSH session.
"bamboo.password_variable_name" is the global variable which I am using here as the password. Name of that Global Variable is - "password_variable_name"
Prerequisites:
expect - You have to get the binary of "expect" installed.
Was this helpful?