How to use Bamboo Password Variable to SSH with Script task

Still need help?

The Atlassian Community is here for you.

Ask the community

The below code only works on Linux/Mac OS based system.

Purpose

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:

    #!/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.





Last modified on Dec 5, 2019

Was this helpful?

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