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

相关推荐
lsc_blog10 小时前
年底还在招的岗位,先确认缺口和到岗要求
git·缓存·ci/cd·职场和发展·github
AKA__Zas14 小时前
接口自动化测试(1.0 初认识
python·ci/cd·学习方法
修心光1 天前
记录一次,jenkins打包异常问题
运维·jenkins
后台模板学习2 天前
GitHub Actions 与 Jenkins 在日志监
运维·github·jenkins
colinu2 天前
Create gitlab-runner
gitlab
十二同学啊2 天前
Go 工程化详解:项目结构、代码规范、测试体系与 CI/CD 实践
ci/cd·golang·代码规范
Sakura_j_h_2 天前
GitHub Actions 打包 Windows exe:中文编码与产物上传
windows·ci/cd·打包发布·github·pyinstaller·github actions
master3363 天前
GitLab 10.x → 19.5.x 升级路线图
gitlab
砚底藏山河3 天前
量化回测可复现流水线CI化
java·python·ci/cd·金融
X1A0RAN3 天前
Jenkins CI 流水线优化实践:基于提交指纹的任务缓存
缓存·ci/cd·jenkins