使用 bash 脚本执行 git 克隆,无法读取存储库密码
Doing git clone with bash script, could not read Password for repository
我正在尝试通过 CloudFormation 部署 Amazon EC2 实例,并且正在尝试使用带有 cfn-init 的 bash 脚本克隆存储库。
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#! /bin/bash -xe\n",
"yum install -y aws-cfn-bootstrap\n",
"/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" }
]]}}
}
然而,当我部署 EC2 实例时,我可以从 cloud-init-output.log
看到 git 克隆失败,这是错误:
fatal: could not read Password for 'https://username@gitlab.com': No such device or address
如何使用bash脚本正确输入密码?我试过 yes
发现 here
像这样添加密码(您也可以将其设置为参数)
git clone https://user:password@gitlab.com/....git
在您的情况下,它将是:
"git clone https://", { "Ref": "GitLabUsn" },":", { "Ref": "GitLabPwd" },"@gitlab.com/user/repository.git \n"
我正在尝试通过 CloudFormation 部署 Amazon EC2 实例,并且正在尝试使用带有 cfn-init 的 bash 脚本克隆存储库。
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#! /bin/bash -xe\n",
"yum install -y aws-cfn-bootstrap\n",
"/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" }
]]}}
}
然而,当我部署 EC2 实例时,我可以从 cloud-init-output.log
看到 git 克隆失败,这是错误:
fatal: could not read Password for 'https://username@gitlab.com': No such device or address
如何使用bash脚本正确输入密码?我试过 yes
发现 here
像这样添加密码(您也可以将其设置为参数)
git clone https://user:password@gitlab.com/....git
在您的情况下,它将是:
"git clone https://", { "Ref": "GitLabUsn" },":", { "Ref": "GitLabPwd" },"@gitlab.com/user/repository.git \n"