Can you wait and set Bamboo Variables in an inline script? Edited

I am trying to fire up an EC2 instance, wait until it is a "running" state, then set a bamboo variable to the newly created instance id for use to deploy.

Reference: Bash script . I know that is .sh and not windows, but it proves it can be done, and I am working on Windows 2012 based EC2 configurations.

So I set a Bamboo Variable via the Plan Configuration -> Variables(tab)

Name: instance_id, Value: i-xxxxxxx

Then i have a script task (cmd, inline):

echo ${bamboo.instance_id}

EC2_RUN_RESULT=aws ec2 run-instances --image-id ami-xxxxxxx --instance-type t2.micro --key-name KeyName --security-groups launchSecurityGroup

set ${bamboo.instance_id}=EC2_RUN_RESULT.id

Doesn't work.

set ${bamboo.instance_id}="abc123"

echo ${bamboo.instance_id}

Only returns "i-xxxxxxx"

How do I set a variable? And how do I setup a loop that will wait until the EC2 Instance is in a running state?

 

Thank you in advance!

1 answer

So I've answered most of the question(s) except how to pass variable to another task.

|||| -> Storing a variable.

You must use a Windows PowerShell (can be inline or a script)

$ec2_result = aws ec2 discribe-instances --instance-id a1234bc567defg --query "Instances[].State[].Name" --output | Out-String

Then you can use it where ever you need to 

Write-Host $ec2_result

*NOTE: make sure you add trim so you don't get errors. I.e.

 

|||| -> Waiting for an operation

In your Windows PowerShell (inline or script); this is how I did it.

$state = "pending"
Do{
        Start-Sleep -s 15
        $state = aws ec2 discribe-instance-status --instance-id $instance_id.Trim() --query "InstanceStatuses[].InstanceState[].Name" --output text | Out-String
} Until ($state.Trim() -eq "running")

So how do I pass the $instance_id to another script? I cannot assign it to a bamboo.variable?

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,096 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot