【发布时间】:2021-01-19 18:47:13
【问题描述】:
我正在尝试将代码从 GitLab 部署到 EC2 实例。但是,当我运行管道时出现以下错误
/home/gitlab-runner/.ssh/config: line 1: Bad configuration option: \342\200\234host
/home/gitlab-runner/.ssh/config: terminating, 1 bad configuration options
这是我正在使用的 .gitlab-ci.yml 文件。
stages:
- QAenv
- Prod
Deploy to Staging:
stage: QAenv
tags:
- QA
before_script:
# Generates to connect to the AWS unit the SSH key.
- mkdir -p ~/.ssh
- echo -e “$SSH_PRIVATE_KEY” > ~/.ssh/id_rsa
# Sets the permission to 600 to prevent a problem with AWS
# that it’s too unprotected.
- chmod 600 ~/.ssh/id_rsa
- 'echo -e “Host *\n\tStrictHostKeyChecking no\n\n” > ~/.ssh/config'
script:
- bash ./gitlab-deploy/.gitlab-deploy.staging.sh
environment:
name: QAenv
# Exposes a button that when clicked take you to the defined URL:
url: https://your.url.com
下面是我设置的 .gitlab-deploy.staging.sh 文件以部署到我的服务器。
# !/bin/bash
# Get servers list:
set — f
# Variables from GitLab server:
# Note: They can’t have spaces!!
string=$DEPLOY_SERVER
array=(${string//,/ })
for i in "${!array[@]}"; do
echo "Deploy project on server ${array[i]}"
ssh ubuntu@${array[i]} "cd /opt/bau && git pull origin master"
done
我检查了我的 .ssh/config 文件内容,下面是我可以看到的内容。
ubuntu@:/home/gitlab-runner/.ssh$ cat config
“Host *ntStrictHostKeyChecking nonn”
关于我做错了什么以及我应该做出哪些改变有什么想法吗?
【问题讨论】:
-
用
"替换所有“。 -
顺便说一句:将
# !替换为#!。 -
您还需要修正右引号。
标签: bash git amazon-web-services amazon-ec2 gitlab