0

Need some guidance. I am trying to deploy a container in remote server and used groovy script to do this task. I am getting error like below,

[2025-04-02T04:26:43.369Z] + ssh -o StrictHostKeyChecking=no -l ec2-user 13.127.63.170 'docker run -itd -p 80:80 475798544865.dkr.ecr.ap-south-1.amazonaws.com/my-jenkins-project:"${ECR_Tag}"' [2025-04-02T04:26:43.369Z] docker: invalid reference format

Can someone please check and let me know what wrong is there with this command (marked in *) ?

Pipeline stage,


stage ('Docker-deploy-prod') {
            
            steps {
                echo "***********************************Starting on remote production server****************************"
                sshagent(['Production']) {
                sh '''
                ssh -o StrictHostKeyChecking=no -l ec2-user 13.127.63.170 'aws ecr get-login-password --region ap-south-1 | sudo docker login --username AWS --password-stdin 475798544865.dkr.ecr.ap-south-1.amazonaws.com'
                ***ssh -o StrictHostKeyChecking=no -l ec2-user 13.127.63.170 'docker run -itd -p 80:80 475798544865.dkr.ecr.ap-south-1.amazonaws.com/my-jenkins-project:"${ECR_Tag}"'***
                '''
               }
            }
        }
5
  • The aws ecr get-login-password command is very likely to output the password in the aws command's default format, which is JSON. Does the docker login --password-stdin command expect the password as JSON?
    – Sotto Voce
    Commented Apr 2 at 16:26
  • Can you check two things: 1 - That you are logged in to ECR during the 2nd command, and the new SSH didn't terminate the session? 2 - That you can see the variable ${ECR_Tag}? What happens when you run just echo ${ECR_Tag}?
    – Uberhumus
    Commented Apr 2 at 20:28
  • @SottoVoce - That first command when I am running separately doesnt have any issues,[root@ip-172-31-40-200 jenkins-ecr-pipeline]# aws ecr get-login-password --region ap-south-1 | sudo docker login --username AWS --password-stdin 475798544865.dkr.ecr.ap-south-1.amazonaws.com WARNING! Your credentials are stored unencrypted in '/root/.docker/config.json'. Configure a credential helper to remove this warning. See docs.docker.com/go/credential-store Login Succeeded Commented Apr 3 at 5:57
  • @Uberhumus - So login is succeeded in first command itself. I am not fully sure how to verify that new ssh statement is terminating the session. Commented Apr 3 at 6:05
  • @PiyushNikhade did you try hardcoding a tag? For example ssh -o StrictHostKeyChecking=no -l ec2-user 13.127.63.170 'docker run -itd -p 80:80 475798544865.dkr.ecr.ap-south-1.amazonaws.com/my-jenkins-project:latest'?
    – Uberhumus
    Commented Apr 3 at 8:33

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.