gitlab-ci - 无法用 gitlab 实现 CI/CD
问题描述
我是 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 时,代码应该自动部署在服务器上。谁能帮我解决这个问题?我真的很沮丧,很长一段时间都无法修复它。
提前致谢。
解决方案
推荐阅读
- ios - iOS 目标而非 macOS 目标上的 NSAssert 中断(具有多个目标的工作区)
- c# - 如何在 ASP.NET Core MVC 中对 RazorViewEngineOptions 进行单元测试?
- asp.net - 使用 Visual Studio 负载测试附加 DotTrace 性能分析器
- python - Seaborn.countplot :按数量排序,也按类别排序?
- java - 格式化日期 ddmmyy Java
- regex - RegEx:从字符串中提取格式化的数字(如果存在)
- abap - 使用 cl_salv_table 显示数据时发生意外的数据库提交
- html - BootstrapVue 两个工具提示出现在同一个元素上同时具有不同的目标?
- javascript - 使用 jQuery 检测元素上的触摸滑动
- r - 查找列表中满足R中条件的元素的索引