我一直在尝试为我的项目设置CD.我的Gitlab CI跑步者和我的项目将在同一台服务器上.我已经关注https://docs.gitlab.com/ee/ci/examples/deployment/composer-npm-deploy.html但我一直收到SSH Permission denied (publickey,password).错误.我在项目设置中正确设置了所有变量,私钥和其他变量.
我用ssh-keygen -t rsa -C "my.email@example.com" -b 4096命令创建了我的ssh密钥,没有密码短语,并PRODUCTION_PRIVATE_KEY用~/.ssh/id_rsa文件内容设置我的变量.
这是我的gitlab-ci.yml:
stages:
- deploy
deploy_production:
stage: deploy
image: tetraweb/php
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$PRODUCTION_PRIVATE_KEY")
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- apt-get install rsync
script:
- ssh $PRODUCTION_SERVER_USER@$PRODUCTION_SERVER
- hostname
only:
- …Run Code Online (Sandbox Code Playgroud) 我正在尝试ci通过docker执行器在本地运行管道以进行调试:
gitlab-runner exec docker <job_name>
Run Code Online (Sandbox Code Playgroud)
在某个时间点,它需要克隆一个私有git存储库。
我正在使用gitlab 建议的典型配方。
variables:
MY_PRIVATE_KEY: <my_private_key>
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$MY_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
Run Code Online (Sandbox Code Playgroud)
但是,当尝试将密钥添加到代理时:
$ ssh-add <(echo "$MY_PRIVATE_KEY")
Enter passphrase for /dev/fd/63: Running after script...
ERROR: Job failed: exit code 1
FATAL: exit code 1 …Run Code Online (Sandbox Code Playgroud)