0

我是 CI/CD 的新手。我创建了一个简单的 .gitlab-ci.yml,我可以进入服务器,但最后它显示给我

bash: keys/relation-fe: Permission denied
Cleaning up file based variables
ERROR: Job failed: exit status 1

在我的 gitlab 管道上。我的 gitlab-ci.yml 文件配置如下。

deploy-prod:
  tags:
    - ci
  stage: deploy
  only:
    - master
  before_script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - 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'
  script:
    - bash .gitlab-deploy-prod.sh

和 deploy-prod.sh 文件

#!/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-add")" keys/relation-fe && cd htdocs/relation-fe/ && git pull "
done

我的目标是每当我提交更改并将我的代码推送到 GitLab 时,代码应该自动部署在服务器上。谁能帮我解决这个问题?我真的很沮丧,很长一段时间都无法修复它。

提前致谢。

4

0 回答 0