1、Jenkins创建
2、itLab+Jenkins实现持续集成+自动化部署
3、代码传输rsync,免密登录配置ssh密钥
如果免密登录不生效,则按照如下设置接收文件服务器文件夹权限
cd /home
chmod 600 app/.ssh/authorized_keys
chmod 700 app/.ssh
chmod 755 app
Jenkinsfile文件代码
pipeline {
agent any
stages {
stage('backup') {// 备份
when { environment name: 'deploy_env', value: 'publish' }
steps {
sh label: '备份上次发布dist',
script:
'''
pwd
rsync -avzr --delete ./dist ../open-his-backup
'''
}
}
stage('checkout') {//拉取新代码
when { environment name: 'deploy_env', value: 'publish' }
steps {
git credentialsId: 'ssh_id', url: 'ssh://git@10.1.6.xx:2222/his/open-his.git'
}
}
stage('transfer') { //发布到服务器
when { environment name: 'deploy_env', value: 'publish' }
steps {
sh label: '发布到服务器',
script:
'''
pwd
rsync -avzr --delete ./dist app@10.1.6.xxx:/home/app/open-his
'''
}
}
stage("rollback") {
when { environment name: 'deploy_env', value: 'rollback' }
steps {
sh label: '回滚到上次发布',
script:
'''
pwd
rsync -avzr --delete ../open-his-backup/dist app@10.1.6.xxx:/home/app/open-his
'''
}
}
}
}
相关参考文件:
GitLab+Jenkins实现持续集成+自动化部署(很全)
https://www.cnblogs.com/yanjieli/p/10613212.html
让Jenkins执行GitHub上的pipeline脚本
https://blog.csdn.net/boling_cavalry/article/details/100857361