Open gpj1 opened 5 years ago
The issue is that aws ecr get-login
is returning with Windows line ending
I ended up solving this with a little bash script where aws
is an alias like you have listed above ^^
ECR=$(aws ecr get-login --no-include-email --region ${AWS_REGION})
echo "creating login temp file"
_ECR=$(echo ${ECR} | tr -d '\r')
echo ${_ECR} > ecr.out
echo "login into ecr"
$(cat ecr.out)
echo "pushing image to ecr"
docker push ${URL}
echo "removing temp file"
rm ecr.out```
ECR=$(docker exec -it guide-aws sh -c 'aws ecr get-login --no-include-email --region ${AWS_REGION}')
echo "creating login temp file"
_ECR=$(echo ${ECR} | tr -d '\r')
echo ${_ECR} > ecr.out
echo 'login into ecr'
$(cat ecr.out)
echo "removing temp file"
rm ecr.out
This command works well in environments without the aws plug-in.
inspired by JasonChinsen 's option :D
Thanks for the help, much appreciated. This also works with eval for a shorter script, at least in my case.
LOGIN_WITH_SPACES=$(aws ecr get-login --no-include-email --region ${AWS_REGION}) LOGIN_WITHOUT_SPACES=$(echo ${LOGIN_WITH_SPACES} | tr -d '\r') eval $LOGIN_WITHOUT_SPACES
Thanks for the help, much appreciated. This also works with eval for a shorter script, at least in my case.
LOGIN_WITH_SPACES=$(aws ecr get-login --no-include-email --region ${AWS_REGION}) LOGIN_WITHOUT_SPACES=$(echo ${LOGIN_WITH_SPACES} | tr -d '\r') eval $LOGIN_WITHOUT_SPACES
Thanks! To make it short in one command:
$(echo $(aws ecr get-login --no-include-email --region cn-north-1) | tr -d '\r')
Thanks for this!
btw, without using echo
from @totogo answer:
$(aws ecr get-login --no-include-email --region us-east-1 | tr -d '\r')
I'm using this
mesosphere/aws-cli
container in my CI pipeline for purpose of pushing an docker image to AWS ECR and below is mysh
step of Jenkins Pipelinesh """ alias aws='docker run --rm -t \$(tty &>/dev/null && echo "-i") -e AWS_ACCESS_KEY_ID=xxxxxx -e AWS_SECRET_ACCESS_KEY=xxxxxx -e AWS_DEFAULT_REGION=ap-south-1 -v \$(pwd):/project mesosphere/aws-cli' \$(aws ecr get-login --no-include-email) """
Output of this step during Jenkins build is:
......dmQxNTJrVzBIQVFEa1RESDJQUE0xUFJSbDg3bDFaRU5XMlYxenYzMEEvNUdLVWNDeVRhZGYyS0hoMnkvM3h1aC9Ta1VLdy9sQTcvK3NHYWFRUkUzUGZJRW5XR3c3T010QmErd2hlZFRhL1JLa3ciLCJkYXRha2V5IjoiQVFJQkFIaUhXYVlUblJVV0NibnorN0x2TUcrQVB2VEh6SGxCVVE5RnFFbVYyNkJkd3dHWlp3cW9vVVJTcUFBblNVY1RQdnBYQUFBQWZqQjhCZ2txaGtpRzl3MEJCd2FnYnpCdEFnRUFNR2dHQ1NxR1NJYjNEUUVIQVRBZUJnbGdoa2dCWlFNRUFTNHdFUVFNMG1kV2VuM3VrYXFPNEJyaUFnRVFnRHVPOWdXVVJtTkhEc3JrZC9YSkRWdlQ5Y0JORGpnU1dzbFQxMHpqSzVUV3VabWJpdVFZQThrZGxoeVFBM2xTREsyWlBETHlNVkFVdW12NVJBPT0iLCJ2ZXJzaW9uIjoiMiIsInR5cGUiOiJEQVRBX0tFWSIsImV4cGlyYXRpb24iOjE1NTA5NTE0MDV9 'https://xxxxxxxxxxx.dkr.ecr.ap-south-1.amazonaws.com ' WARNING! Using --password via the CLI is insecure. Use --password-stdin. Error response from daemon: unable to parse server address: parse https://xxxxxxxxxxx.dkr.ecr.ap-south-1.amazonaws.com : invalid character "\r" in host name