Gitlab和Jenkins集成 实现CI (三)

Gitlab和Jenkins集成 实现CI (一)
Gitlab和Jenkins集成 实现CI (二)
Gitlab和Jenkins集成 实现CI (三)

自动部署

配置免密ssh

进入http服务器

生成ssh密钥
shell 复制代码
ssh-keygen -t rsa

进入jenkins(容器)

拷贝公钥
shell 复制代码
ssh-copy-id http服务器用户名@http服务器ip
#输入http服务器密码

配置jenkis构建触发器

生成拷贝脚本
shell 复制代码
vi /var/jenkins_home/scp_dev_env.sh

#!/bin/sh

scp /var/jenkins_home/workspace/jenkins项目名称/* http服务器用户名@http服务器ip:/home/docker/www/项目根目录/
ssh http服务器用户名@http服务器ip 'composer -V' # 这里是php执行composer,如果是java可以执行maven等

# 设置执行权限
chmod +x /var/jenkins_home/scp_dev_env.sh

# 运行异常脚本,保证脚本无异常,可正常执行得到想要的结果
/bin/sh /var/jenkins_home/scp_dev_env.sh

#去http服务器根目录查看拷贝是否正确
配置构建步骤(Build Steps)

进入项目
Configure Build Steps Add build step 选择Run with timeout Run with timeout Time-out strategy 按照实际选择超时机制 Build Step 选择Execute shell Command 填写脚本路径

注意,如果无需超时设置,需要保证脚本无论执行多久一定成功,在Add build step的时候直接选择Execute shell,其他配置不变

相关推荐
修心光10 小时前
记录一次,jenkins打包异常问题
运维·jenkins
后台模板学习12 小时前
GitHub Actions 与 Jenkins 在日志监
运维·github·jenkins
colinu13 小时前
Create gitlab-runner
gitlab
十二同学啊14 小时前
Go 工程化详解:项目结构、代码规范、测试体系与 CI/CD 实践
ci/cd·golang·代码规范
Sakura_j_h_1 天前
GitHub Actions 打包 Windows exe:中文编码与产物上传
windows·ci/cd·打包发布·github·pyinstaller·github actions
master3361 天前
GitLab 10.x → 19.5.x 升级路线图
gitlab
砚底藏山河1 天前
量化回测可复现流水线CI化
java·python·ci/cd·金融
X1A0RAN2 天前
Jenkins CI 流水线优化实践:基于提交指纹的任务缓存
缓存·ci/cd·jenkins
长不大的杨瑞杰2 天前
OpenCode v2 GitLab 集成实战:Issue 驱动开发、MR 审查与 CI/CD 最小权限
人工智能·ci/cd·gitlab·ai编程·opencode
北风toto3 天前
Elasticsearch 8.2.3 快照迁移实战:从备份到恢复的完整指南
大数据·elasticsearch·jenkins