使用 GitLab 的 CD,Bash 脚本不起作用

使用 GitLab 的 CD,Bash 脚本不起作用

我正在与持续集成、光盘但不幸的是我搞砸了 shell 脚本。在我的 gitlab-ci.yml 文件中,我在部署时调用了 bashscript。但不幸的是,每当我想使用命令拉取时,响应都会失败。对于这个 bash 脚本我的回应是

#!/bin/bash

# Get server list 
set -f
string=$DEPLOY_SERVER_IP
array=(${string//,/ })

# Iterate servers for deploy and pull last commit 
for i in "${!array[@]}"; do
  echo "Deploy project on server ${array[i]}"
  ssh bitnami@${array[i]} " ssh-agent bash && ssh-add keys/relation-fe && cd htdocs/relation-fe/ && git pull origin master "
done

我的回答是这样的

Executing "step_script" stage of the job script
$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 21206
$ mkdir -p ~/.ssh
$ echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
$ chmod 600 ~/.ssh/id_rsa
$ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ bash .gitlab-deploy-prod.sh
Deploy project on server 1.2.3.4
Could not open a connection to your authentication agent.
Cleaning up file based variables
ERROR: Job failed: exit status 1

那么我该如何解决这个错误呢?该错误表明 gitlab 已成功访问我的服务器,但在运行 ssh-agent 并通过 ssh-key 添加密钥时,脚本无法执行命令。那么错误就来自这里。我对 bash 脚本和 shell 脚本的事情感到困惑。所以我无法从我的脚本中找出错误。我能够在 git Push 上创建文件,但不能使用 ssh-key 进行身份验证后提取内容谁能帮我这个?

答案1

看起来 Gitlab 没有连接到您的跑步者,这与您的服务器不同。确保您的运行程序可用并且 gitlab 可以连接到它。

相关内容