由于是内部私有项目,为了方便连接ssh时,使用了密码
.gitlab-ci.yml
stages:
- deploy
# 部署
deploy:
stage: deploy
image: alpine:latest
variables:
TARGET_DIR: /opt/1panel/apps/openresty/openresty/www/sites/scripts/index/
before_script:
- apk update
- apk add openssh
- apk add rsync
- apk add sshpass
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "StrictHostKeyChecking no" >> ~/.ssh/known_hosts
- export SSHPASS=$SERVER_PASSWORD
script:
- sshpass -e rsync -azv --delete --exclude='.*' . $SERVER_USER@$SERVER_HOST:$TARGET_DIR
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
报错信息:
Host key verification failed.
rsync error: unexplained error (code 255) at rsync.c(713) [sender=3.2.5]
ERROR: Job failed: exit code 6
解决
添加-e "ssh -o StrictHostKeyChecking=no"
选项
修改同步命令为
sshpass -e rsync -azv -e "ssh -o StrictHostKeyChecking=no" --delete --exclude='.*' . $SERVER_USER@$SERVER_HOST:$TARGET_DIR
Comments | NOTHING