Jenkins 多分支流水线(SVN)
实际应用过程中,一般多分支流水线的方式用得比较多一些,
master 对应 生成环境
develop 对应 测试环境,
将不同分支的代码构建到不同的环境中
添加 Jenkinsfile 文件
Jenkinsfile 内容见:Jenkins Pipeline 流水线 - 完整构建 Pipeline Script 脚本
DevOps/trunk 专门用来放运维脚本

提交 Jenkins 到 SVN
注意代码要放到 trunk,branches 等 分支中
创建多分支流任务




运行

多个 stage 使用不同代理,会在每一步都进行SVN 的切换

完整 pipeline 脚本
pipeline {
agent { label 'JenkinsAgent' }
parameters {
string defaultValue: '4.2', description: '编译版本号', name: 'BUILD_NUMBER'
}
tools {
maven 'Maven36' //添加 Maven 工具
}
stages {
stage('CheckOut SVN Code') {
steps {
checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'c3b4ef0e-b414-4376-8a21-2e08e1c84dfb', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'SVN地址']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']]) //该脚本由流水线语法自动生成
echo 'CheckOut SVN Success'
}
}
// Jenkinsfile 的 地址和代码不在同一个仓库下时,需要用这种嵌套的方式,否则,代码刚拉下来,执行第二个 stage 时就被删除了。
stage('Maven Build') {
steps {
bat 'mvn clean package -Dmaven.test.skip=true'
echo 'Maven Build Success'
}
}
//Docker 在 3.88服务器
stage('Docker Build 、Push Repository') {
steps {
#sourceFiles windows下注意 用 \\ 否则可能上传时导致文件找不到。
sshPublisher(publishers: [sshPublisherDesc(configName: 'DockerPublishSSH', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'PipelineDemo', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'target/demojenkins.jar'), sshTransfer(cleanRemote: false, excludes: '', execCommand: '''
cd /opt/jenkins/PipelineDemo
docker build -t registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:${BUILD_NUMBER} .
docker login -u hi帐号ID@aliyun.com -p 密码 registry.cn-shanghai.aliyuncs.com
docker push registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:${BUILD_NUMBER}''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'PipelineDemo', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'Dockerfile')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
echo 'Docker SUCCESS'
}
}
//K8S 在 3.181服务器
stage('K8S Deployment') {
steps {
script {
def remote = [:]
remote.name = 'K8S Server'
remote.host = '172.16.3.181'
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: 'K8SMaster', passwordVariable: 'password', usernameVariable: 'username')]) {
remote.user = "${username}" // 变量要使用“”双引号
remote.password = "${password}" //把凭证中的用户名、密码拿出来给 remote参数
}
sshCommand remote: remote, command: "kubectl set image deployment/javademo1 vipsoft=registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:${BUILD_NUMBER}"
echo 'K8S Deployment SUCCESS'
}
}
}
}
}


Jenkins 多分支流水线(SVN)的更多相关文章
- Jenkins打造多分支流水线指南
overview: 多分支工作流程带来了以下几个关键能力: 在代码仓库中,每个新分支都有自己单独的工作流水线(job). 每个工作流水线都记录了对应分支的构建和变更历史. 可以自定义设置流水线随着分支 ...
- CI/CD之Gitlab集成Jenkins多分支pipeline实现质量检测和自动发布
本次实施主要实现: 代码提交gitlab,自动触发Jenkins构建 gitlab发起Merge Request, 需要Jenkins检查通过才可以merge,实现代码review和质量管控 gitl ...
- Jenkins + Pipeline 构建流水线发布
Jenkins + Pipeline 构建流水线发布 利用Jenkins的Pipeline配置发布流水线 参考: https://jenkins.io/doc/pipeline/tour/depl ...
- Jenkins多分支构建
目录 一.创建多分支pipeline 二.根据分支部署 gitlab触发与多分支 Generic Webhook多分支 一.创建多分支pipeline 在实际中,需要多分支同时进行开发.如果每个分支都 ...
- 如何在 Jenkins CI/CD 流水线中保护密钥?
CI/CD 流水线是 DevOps 团队软件交付过程的基本组成部分.该流水线利用自动化和持续监控来实现软件的无缝交付.通过持续自动化,确保 CI/CD 流水线每一步的安全性非常重要.在流水线的各个阶段 ...
- DEVOPS技术实践_09:Jenkins多分支管道
简介 多分支的管道是在jenkins2.x中新增的功能 . 多分支管道允许你针对分布式的控制器的每个分支创建一个管道. 下图是对它的一个描述.使用jenkinsfile去创建多分支的管道,jenkin ...
- 9.Jenkins进阶之流水线pipeline基础使用实践(2)
目录一览: 0x01 基础实践 0x02 进阶实践 (1) Sonarqube 代码质量检测之 Pipeline Script from SCM (2) Gitlab 自动触发构建之 Pipeline ...
- 8.Jenkins进阶之流水线pipeline基础使用实践(1)
目录一览: 0x01 基础实践 (1) Maven 构建之 Pipeline Script (2) Maven 构建之 Pipeline Script from SCM (3) Jenkins pi ...
- 7.Jenkins进阶之流水线pipeline语法入门学习(2)
目录一览: (2) Declarative Pipeline Syntax 2.1) Sections - 章节 2.2) Directives - 指令 2.3) Sequential Stages ...
- 6.Jenkins进阶之流水线pipeline语法入门学习(1)
目录一览: 0x00 前言简述 Pipeline 介绍 Pipeline 基础知识 Pipeline 扩展共享库 BlueOcean 介绍 0x01 Pipeline Syntax (0) Groov ...
随机推荐
- 接口开放太麻烦?试试阿里云API网关吧
前言 我在多方合作时,系统间的交互是怎么做的?这篇文章中写过一些多方合作时接口的调用规则和例子,然而,接口开放所涉及的安全.权限.监控.流量控制等问题,可不是简简单单就可以解决的,这一般需要专业的开放 ...
- NewsCenter
打开界面有一个搜索框 抓包查看是post形式提交的数据包 这时候试试sql注入,万能密码直接全都显示,那就说明存在sql注入漏洞 这里试试用sqlmap自动注入试试(POST类型的sql注入第一次尝试 ...
- require()、import、import()有哪些区别?
require().import.import()是我们常用的引入模块的三种方式,代码中几乎处处用到.如果对它们存在模糊,就会在工作过程中不断产生困惑,更无法做到对它们的使用挥洒自如.今天我们来一起捋 ...
- van-dialog弹窗异步关闭-校验表单
van-dialog弹窗异步关闭 有时候我们需要通过弹窗去处理表单数据,在原生微信小程序配合vant组件中有多种方式实现,其中UI美观度最高的就是通过van-dialog嵌套表单实现. 通常表单涉及到 ...
- A-B数对 (hash映射)
题目大意: 第一行输入N,C 第二行输入n个数字 输出,求A - B = C的数对个数 样例 4 1 1 1 2 3 输出 3 思路:用STL容器map,map<num, times>,建 ...
- 本地Stackedit Markdown编辑器设置远程访问
StackEdit是一个受欢迎的Markdown编辑器,在GitHub上拥有20.7k Star!,它支持将Markdown笔记保存到多个仓库,包括Gitee.GitHub和Gitea.此在线笔记工具 ...
- Gmail 发送邮件报警
亲测好使 import smtplib import email.mime.text import time # my test mail mail_username = 'XXXXXXXXXXX@g ...
- 将mysql的输出文本写回mysql
1 准备工作 1.1 环境准备 操作系统:Microsoft Windows 10 专业工作站版 软件版本:Python 3.9.6 第三方包: pip install pandas2.1.0 pip ...
- [ABC245G] Foreign Friends
Problem Statement There are $N$ people and $K$ nations, labeled as Person $1$, Person $2$, $\ldots$, ...
- python tkinter使用(十一)
python tkinter使用(十一) 本篇文章主要讲下tkinter 窗口的一些属性,以及实现无法关闭的窗口中遇到的一些问题. #!/usr/bin/python3 # -*- coding: U ...