Gitlab CI - Docker push to AWS ECR

1.3k views Asked by At

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
1

There are 1 answers

0
Jackie On