Skip to content
Advertisement

Doing git clone with bash script, could not read Password for repository

I’m trying to deploy Amazon EC2 instance through CloudFormation and I’m trying to clone a repository with a bash script with cfn-init.

"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
                "#! /bin/bash -xen",
                "yum install -y aws-cfn-bootstrapn",
                "/opt/aws/bin/cfn-init -v ",
                "       --stack ", { "Ref" : "AWS::StackName" },
                "       --resource DocumentationInstance ",
                "       --configsets Install ",
                "       --region ", { "Ref" : "AWS::Region" }, "n",
                "git clone https://", { "Ref": "GitLabUsn" },"@gitlab.com/user/repository.git n", { "Ref": "GitLabPwd" }  
                ]]}}
        }

However, when I deploy the EC2 instance, I can see from cloud-init-output.log that the git clone fails, and this is the error:

fatal: could not read Password for 'https://username@gitlab.com': No such device or address

How can I input the password with the bash script correctly? I’ve tried the yes found here

Advertisement

Answer

ADD the password like this(your can also set it as parameter) git clone https://user:password@gitlab.com/....git

In your case, it will be :

"git clone https://", { "Ref": "GitLabUsn" },":", { "Ref": "GitLabPwd" },"@gitlab.com/user/repository.git n"
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement