0

I am having problems running commands on an EC2 Instance from my Bamboo server. I have a command generated from the Run Command in the AWS Console. I place that command in a script on my bamboo server and run it:

aws ssm send-command --document-name "AWS-RunPowerShellScript" --targets '{\"Key\":\"tag:Name\",\"Values\":[\"Auto-Scaling-Group\"]}' --parameters '{\"commands\":[\"$fileEXE = \\\"C:\\\\Program Files (x86)\\\\NUnit\\\\NUnit.ConsoleRunner.3.7.0\\\\tools\\\\nunit3-console.exe\\\\\\\"\",\"$testDll = \\\"C:\\\\TestFramework\\\\TestFramework\\\\Tests\\\\bin\\\\Debug\\\\TESTS.dll\\\"\",\"[System.Diagnostics.Process]::Start($fileEXE,$testDll)\"]}' --comment "Run Test UI Testing" --timeout-seconds 600 --region us-east-1

It does run the tests. But it runs the Chrome.exe browser AND the chromedriver.exe as background processes. This throws a NoSuchWindowException because there is no browser showing up...

I can run the same command in PowerShell on the instance locally: (*Note that this is the same command I pasted into the Run Command console to generate the code mentioned above.)

$fileEXE = "C:\Program Files (x86)\NUnit\NUnit.ConsoleRunner.3.7.0\tools\nunit3-console.exe\"
$testDll = "C:\TestFramework\TestFramework\Tests\bin\Debug\TESTS.dll"
[System.Diagnostics.Process]::Start($fileEXE,$testDll)

It works just fine. chromedriver.exe is a background process and chrome.exe (the browser) is a regular app that works like normal.

I believe my problem is how Run Command is running my test program.

What is the difference between Run Command (send-command) and running the PowerShell commands locally? Shouldn't it do the same thing?

kenorb
  • 155,785
  • 88
  • 678
  • 743
J-Roel
  • 520
  • 1
  • 4
  • 21

1 Answers1

0

I think there is a mess up with quotes and the way how they're escaped.

See: How to escape a double quote inside double quotes?

This version should look much simpler:

CMD='$fileEXE = "C:\Program Files (x86)\NUnit\NUnit.ConsoleRunner.3.7.0\tools\nunit3-console.exe";'
CMD+='$testDll = "C:\TestFramework\TestFramework\Tests\bin\Debug\TESTS.dll";'
CMD+='[System.Diagnostics.Process]::Start($fileEXE,$testDll);'

aws ssm send-command --document-name "AWS-RunPowerShellScript" \
  --filters "Name=tag:Name,Values=Auto-Scaling-Group" \
  --comment "Run Test UI Testing" --timeout-seconds 600 --region us-east-1 \
  --parameters commands="'$CMD'"

Note: Run it in the Bash shell.

kenorb
  • 155,785
  • 88
  • 678
  • 743