0

I spent 5 hours today with no help. Here is the scenario/setup.

1) Windows Server - Gitlab-runner is running, making builds and pushing to docker registry on server for development branch

2) For master branch, I want to push docker image to AWS ECR.

3) I already installed AWS CLI and added to global PATH variable on build server. I can run commands and successfully push to AWS ECR.

4)PROBLEM - When I execute the same script from CI .yml file, it failed. My gitlab-runner is running on "cmd" "shell" mode and my script is in same format. But to get AWS login token, I have to execute following command:

powershell Invoke-Expression -Command (aws ecr get-login --no-include-email)

I can run above command from cmd prompt but when runner tries to execute this, it couldn't identify the "aws".

path of "aws" is "C:\Program Files\Amazon\AWSCLI\bin\aws.exe"

What to do ? Do anyone tried to login to AWS ECR in windows platform using cmd shell script.

UPDATE: Do you think any of the following will work? I don't have access to my server right now, I will test them tomorrow morning.

powershell Invoke-Expression -Command (powershell aws ecr get-login --no-include-email)




OR

powershell $abc = & "C:\Program Files\Amazon\AWSCLI\bin\aws" ecr get-login --no-include-email; Invoke-Expression $abc


OR

powershell

$abc = & "C:\Program Files\Amazon\AWSCLI\bin\aws" ecr get-login --no-include-email
Invoke-Expression $abc;
exit



OR

powershell -command C:\Work\awsbat.ps1


awsbat.ps1 file =

$abc = & "C:\Program Files\Amazon\AWSCLI\bin\aws" ecr get-login --no-include-email

Invoke-Expression $abc

ANSWER:

Option 4 worked for me.

Execute following in gitlab CI yml file:
powershell -command C:\Work\awsbat.ps1


contents of awsbat.ps1 file =

$abc = & "C:\Program Files\Amazon\AWSCLI\bin\aws" ecr get-login --no-include-email
Invoke-Expression $abc
sorabzone
  • 797
  • 5
  • 8
  • aws is in PATH variable, I already verified and tested it. and second option is not working, I already tried to provide full path, it gives syntax error. – sorabzone Sep 19 '18 at 13:41
  • I am wondering, is there any way I can push without AWSCLI. Just use my IAM role ID/Key in docker config or something like that. – sorabzone Sep 19 '18 at 13:43
  • yes, you can leverage on ecr credential helper for that. refer to: https://lwpro2.wordpress.com/2019/10/30/authenticating-amazon-ecr-repositories-for-docker-cli-with-credential-helper/ – Jackie Oct 31 '19 at 02:47

1 Answers1

0

yes, you can leverage on ecr credential helper for that. refer to: https://lwpro2.wordpress.com/2019/10/30/authenticating-amazon-ecr-repositories-for-docker-cli-with-credential-helper/

Jackie
  • 25,199
  • 6
  • 33
  • 24