Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
customer-recall
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tools
customer-recall
Commits
c2158474
Commit
c2158474
authored
Aug 10, 2025
by
罗启
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update .gitlab-ci.yml
parent
c3931ad2
Pipeline
#3145
canceled with stage
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
17 deletions
+7
-17
.gitlab-ci.yml
+7
-17
No files found.
.gitlab-ci.yml
View file @
c2158474
# 定义工作流的各个阶段
,我们这里只需要一个 "deploy" 阶段
# 定义工作流的各个阶段
stages
:
-
deploy
...
...
@@ -7,31 +7,21 @@ deploy_to_production:
# 将这个任务归属到 "deploy" 阶段
stage
:
deploy
# 指定运行此任务的 Docker 镜像
,我们用一个基础镜像
# 指定运行此任务的 Docker 镜像
image
:
alpine:latest
# 在主脚本运行前执行的准备工作
before_script
:
# 安装 ssh 客户端和 ssh-agent
-
'
which
ssh-agent
||
(
apk
add
--update
--no-cache
openssh-client
)'
# 启动 ssh-agent
-
eval $(ssh-agent -s)
# 将存储在 GitLab CI/CD 变量中的私钥添加到 ssh-agent
# $SSH_PRIVATE_KEY 是您需要在 GitLab 网页上设置的变量名
-
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
# 创建 .ssh 目录并设置权限
-
mkdir -p ~/.ssh
-
chmod 700 ~/.ssh
# (可选,但更安全)将服务器的公钥添加到 known_hosts,避免交互式提示
# $SSH_KNOWN_HOSTS 也是一个 CI/CD 变量
-
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
-
chmod 644 ~/.ssh/known_hosts
# 任务的核心执行脚本
script
:
-
echo "准备连接到部署服务器..."
# 使用 ssh 命令连接你的服务器
# $SSH_USER, $SSH_HOST, $SSH_PORT 都是您需要在 GitLab 设置的变量
-
|
ssh -p $SSH_PORT $SSH_USER@$SSH_HOST "
echo '✅ 连接服务器成功,开始执行部署脚本...'
...
...
@@ -48,7 +38,7 @@ deploy_to_production:
echo '🚀 部署流程执行完毕!'
"
# 定义触发此任务的规则
rules
:
# 只有当代码被推送到 master 分支时,才执行这个任务
-
if
:
'
$CI_COMMIT_BRANCH
==
"master"'
\ No newline at end of file
# 使用 "only" 关键字来控制触发分支
# 这段配置表示,这个任务只会在 "master" 分支上运行
only
:
-
master
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment