1

I am trying to pass this powershell command to aws ssm:

$CMD = "docker image inspect $(docker inspect $(docker ps --filter ancestor=.dkr.ecr.us-east-1.amazonaws.com/service:latest -q) --format '{{.Image}}') --format '{{.RepoDigests}}'"
aws ssm send-command --document-name "AWS-RunPowerShellScript" --targets "Key=tag:group,Values=value" --parameters commands="'$CMD'"

But i keep getting this error:

aws : 
At C:\jenkins\workspace\Test_Patch_Update@tmp\durable-4179e3f3\powershellScript.ps1:4 char:33
+ ...             aws ssm send-command --document-name "AWS-RunPowerShellSc ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Error parsing parameter '--parameters': Expected: ',', received: '{' for input:
commands='docker image inspect  $(docker inspect $(docker ps --filter ancestor=dkr.ecr.us-east-1.amazonaws.com/service:latest -q) --format '{{.Image}}') 
--format '{{.RepoDigests}}''

i tried escaping the single quotes by having two-single quotes together '' but it still shows the error:

aws : 
At C:\jenkins\workspace\Test_Patch_Update@tmp\durable-521ed40a\powershellScript.ps1:4 char:33
+ ...             aws ssm send-command --document-name "AWS-RunPowerShellSc ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:String) [], RemoteException
   + FullyQualifiedErrorId : NativeCommandError

Error parsing parameter '--parameters': Expected: ',', received: ''' for input:
commands='docker image inspect  $(docker inspect $(docker ps --filter ancestor=dkr.ecr.us-east-1.amazonaws.com/service:latest -q) --format ''{{.Image}}'') 
--format ''{{.RepoDigests}}'''

PS: i ran it in jenkins

2
  • Can you try a here-string? $CMD = @"docker image inspect $(docker inspect $(docker ps --filter ancestor=905484019492.dkr.ecr.us-east-1.amazonaws.com/rbcloud-service:2020.1.1.0.latest -q) --format '{{.Image}}') --format '{{.RepoDigests}}'"@. Check this for correct syntax. The newlines are important. devblogs.microsoft.com/scripting/… Commented Jul 23, 2020 at 8:54
  • Tested it...it shows the same error :( Commented Jul 23, 2020 at 9:14

1 Answer 1

1

I found the solution!

$CMD = "docker image inspect `$`(docker inspect `$`(docker ps --filter ancestor=dkr.ecr.us-east-1.amazonaws.com/service:latest -q`) --format \\'{{.Image}}\\'`) --format \\'{{.RepoDigests}}\\'"
                        aws ssm send-command --document-name "AWS-RunPowerShellScript" --targets "Key=tag:Patch Group,Values=stage-ecs-windows" --parameters commands="'$CMD'" | ConvertFrom-Json

escaping the single quotes with two backslashes \\ and the dollar and brackets with (`) gave the output.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.