Setting AWS Credentials, Script Task and PowerShell Edited

For a Script Task in your plan. You typically need to set your AWS credentials to point to and use your EC2 instances.

Set-Credentials is the AWS way, but that does not work.

Instead use this?
SET AWS_ACCESS_KEY_ID=$Env:bamboo_AWSAccessKeyId
SET AWS_SECRET_ACCESS_KEY=$Env:bamboo_AWSSecretKeyPassword
SET AWS_DEFAULT_REGION=us-east-1

 

Put it is still not pointing to my EC2 instance correctly. None of my AWS CLI commands work.

3 answers

1 accepted

You can't set the creds in an inline PS. Or, at least I have not been able to find a way to.

Recommend using an inline cmd as follows.

Create a Script task. Use cmd. Set your creds:

@echo off
SET AWS_ACCESS_KEY_ID=${bamboo.AWSAccessKeyId}
SET AWS_SECRET_ACCESS_KEY=${bamboo.AWSSecretKeyPassword}
SET AWS_DEFAULT_REGION=us-east-1

Then, if you need to invoke any PowerShell scripts or other functionality.

Create a Local Agent so you can talk to your local bamboo server. Remember everything works from these agents.
You do not need to setup any capability.
Bamboo's auto-magic will chose the correct agent to build with.

Then in that same inline cmd use the below code to talk to your PowerShell scripts correctly:

powershell -NoProfile -Command "C:\scripts\<myPSscript>.ps1 <arg>; exit $LASTEXITCODE" < NUL

Reference

 

This seems to work well for our needs. HTH.

 

0 votes

@Jeremy Roelfs, when you see output or logs of Script task exception Bamboo will show what environment variables are available for script. Most possible you should use 

${bamboo_AWSAccessKeyId} variable name, not $Env: form

I never could get it working in PowerShell. Not sure what I'm doing wrong. So I switched to a inline cmd. It took some work getting my commands switched to a cmd, but I can set the variables just fine now:

@echo off
SET AWS_ACCESS_KEY_ID=${bamboo.AWSAccessKeyId}
SET AWS_SECRET_ACCESS_KEY=${bamboo.AWSSecretKeyPassword}
SET AWS_DEFAULT_REGION=us-east-1

@Alexey Chystoprudov We have to use PowerShell, so I'm back again... can you please just give me an example?

is it SET AWS_ACCESS_KEY_ID=${bamboo_AWSAccessKeyId}

This is how you set it in PowerShell: $env:AWS_ACCESS_KEY_ID=<key here>

But this: $env:AWS_ACCESS_KEY_ID=${bamboo_AWSAccessKeyId} does not work in the Script Task.

The error I receive is "A positional parameter cannot be found that accepts argument" Real descriptive...

What is it exactly? Can you give me a full example please?

@Jeremy Roelfs, I'm not familiar with PowerShell scripts

According to the related documentation for our (Utoolity's) AWS Credentials Variables task, the following syntax for referencing Bamboo environment variables in PowerShell should work within Bamboo's Script task:

$AWS_ACCESS_KEY_ID = $bamboo_custom_aws_accessKeyId
$AWS_SECRET_ACCESS_KEY = $bamboo_custom_aws_secretAccessKey_password
$AWS_SESSION_TOKEN = $bamboo_custom_aws_sessionToken_password

So given your Bamboo variable names, the following might do the trick in your scenario:

$AWS_ACCESS_KEY_ID = $bamboo_AWSAccessKeyId
$AWS_SECRET_ACCESS_KEY = $bamboo_AWSSecretKeyPassword

 

That does not work either. I think this is working

$AWS_ACCESS_KEY_ID="${bamboo.AWSAccessKeyId}"
$AWS_SECRET_ACCESS_KEY="${bamboo.AWSSecretKeyPassword}"
$AWS_DEFAULT_REGION="us-east-1"

NOPE. The above doesn't work either. Set-AWSCredentials doesn't work... how the do you set the fricken credentials? Seems like pretty basic, straight-forward and common thing? Are we restricted to using a .ps1 file or a cmd?

I can get the key/secret key in the script. You can Write-Host and they show up. I just cannot set the AWS variables so my commands will work

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,066 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