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,其他配置不变

相关推荐
江华森7 小时前
Jenkins CI/CD 实战博客教程
servlet·ci/cd·jenkins
独隅8 小时前
Git/GitHub/GitLab/Gitee 核心对比指南
git·gitlab·github
Bigger8 小时前
记一次坑爹的 Cloudflare Pages 部署:Failed to load module script 是怎么把我的 SPA 搞挂的
前端·ci/cd·浏览器
江华森9 小时前
基于 Git 的自动集成交付(Git-Driven CI/CD)实战
git·ci/cd
开开心心就好10 小时前
清理重复文件释放C盘空间的工具
安全·智能手机·pdf·gitlab·音视频·intellij idea·1024程序员节
李少兄10 小时前
IDE 提示 “GitLab versions older than 14.0 are not supported” 的深度排查与解决方案
ide·gitlab
夜雪闻竹11 小时前
版本管理:npm 发布 + Electron 打包 + CI/CD
ci/cd·npm·node.js·代码规范·chatcrystal
云原生指北11 小时前
告别 Jenkins UI:jk 让 AI Agent 也能操控 Jenkins
jenkins·devops
Forget_85502 天前
RHEL——CICD持续集成与交付
ci/cd
惜年_night2 天前
Docker部署05-GitLab的CI-CD发布
ci/cd·docker·gitlab