当前位置: 首页 > news >正文

持续集成交付CICD:Jira 发布流水线

目录

一、实验

1.环境

2.GitLab 查看项目

3.Jira 远程触发 Jenkins 实现合并 GitLab 分支

4.K8S master节点操作

5.Jira 发布流水线


一、实验

1.环境

(1)主机

表1 主机

主机架构版本IP备注
master1K8S master节点1.20.6192.168.204.180

jenkins slave

(从节点)

jira9.12.1192.168.204.180:8801
node1K8S node节点1.20.6192.168.204.181
node2K8S node节点1.20.6192.168.204.182
jenkins

 jenkins主节点      

2.414.2192.168.204.15:8080

 gitlab runner

(从节点)

harbor私有仓库1.2.2192.168.204.15
gitlabgitlab 主节点     12.10.14192.168.204.8:82

jenkins slave

(从节点)

sonarqube9.6192.168.204.8:9000

(2)查看K8S集群状态

# kubectl get node

2.GitLab 查看项目

(1)GitLab查看前端项目(项目编号为20)

3.Jira 远程触发 Jenkins 实现合并 GitLab 分支

(1)点击系统

(2)管理员入口 (需要输入密码)

(3)修改网络钩子(选择Issue操作事件、Release操作事件来触发)

问题里添加“已更新”

(4)完成修改

(5)修复项目版本

指定1.1.6版本

(6)Jenkins触发流水线,JSON格式转换

(7)拿到关键数据

1)用于创建gitlab 项目名称   
issue.fields.components 2) 用于gitlab 分支名称   
issue.key3)用于gitlab 项目组名称  
issue.fields.project.name4)用于gitlab 特性分支
issue.fields.fixVersions

(8)Jira官网查询issues API接口  (一个Jira项目中的issues对应一个GitLab的特性分支)

Jira REST API examples (atlassian.com)

curl \-D- \-u charlie:charlie \-X GET \-H "Content-Type: application/json" \http://localhost:8080/rest/api/2/search?jql=assignee=charlie

(9)Postman( GET 方式)测试取到Jira 的修复版本信息(fixVersion)

http://192.168.204.180:8801/rest/api/2/search?jql=project= DEVOPS3 AND fixVersion = 1.1.6

(10)GitLab官网查询合并请求 API

Merge requests API | GitLab

POST /projects/:id/merge_requests

(11) Postman (POST 方式)测试创建合并请求

http://192.168.204.8:82/api/v4/projects/20/merge_requests

(12)GitLab查看新增的合并请求

(13)合并请求详细信息

(14)这里先关闭合并请求

(15)Jenkins修改Jira流水线代码

webhookData = readJSON text:  "${webhookData}"//jira 事件
jiraEvent = webhookData.webhookEvent
jiraProjectName = webhookData.issue.fields.project.name// 获取gitlab参数
gitlabProjects = []
gitlabBranchName = webhookData.issue.key
gitlabGroupName =  jiraProjectNamefor (i in webhookData.issue.fields.components){gitlabProjects.add(i["name"])
}//描述信息
currentBuild.description = "Trigger by ${jiraEvent} \n project: ${gitlabProjects} \n branch: ${gitlabBranchName}"pipeline {agent { label "build" }stages {stage("Process") {steps {script {println(gitlabProjects)println(gitlabBranchName)projectIds = GetProjectsId(gitlabGroupName,gitlabProjects)switch(jiraEvent) {case "jira:issue_created":println(projectIds)for (id in projectIds){CreateBranch(id,gitlabBranchName,"master")}breakcase "jira:issue_updated":if (webhookData.issue.fields.fixVersions.size() >= 1){jiraFixVersion = webhookData.issue.fields.fixVersions[0]["name"]//获取fixversion关联的所有issuesissues = GetIssuesByFixVersion(jiraProjectName, jiraFixVersion)// 在issue关联的所有项目创建版本分支for (id in projectIds){CreateBranch(id, "RELEASE-${jiraFixVersion}", "master")    //RELEASE-1.1.6// 创建合并请求  特性分支 > 版本分支for(issue in issues) {CreateMergeRequest(id, issue, "RELEASE-${jiraFixVersion}" )}}break}default:println(error)break}}}}}
}// 创建合并请求def CreateMergeRequest(projectId,sourceBranch,targetBranch) {try {apiUrl = "projects/${projectId}/merge_requests"reqBody = """{"source_branch": "${sourceBranch}","target_branch":"${targetBranch}","title": "${sourceBranch}>>>${targetBranch}byJenkins"}"""response = HttpReq('POST', apiUrl, reqBody)}catch (Exception e) {println(e)}
}// 查询JiraReleaseissuedef GetIssuesByFixVersion(projectName, fixVersion){jql = "project%20=%20${projectName}%20AND%20fixVersion%20=%20${fixVersion}"response = sh returnStdout: true,script: """curl \-u admin:admin \-H "Content-Type: application/json" \--request GET "http://192.168.204.180:8801/rest/api/2/search?jql=${jql}" -s"""response = readJSON text: """ ${response - "\n"} """issues = []for (i in response["issues"]){issues.add(i["key"])}return issues
}// 创建分支
def CreateBranch(projectId,newBranchName,sourceBranchName){try {apiUrl = "projects/${projectId}/repository/branches?branch=${newBranchName}&ref=${sourceBranchName}"response =  HttpReq('POST', apiUrl, "")}catch(Exception e){println(e)}
}// 获取所有项目id
def GetProjectsId(gitlabGroupName,gitlabProjects){gitlabProjectIds = []for (project in gitlabProjects){id = GetProjectId(gitlabGroupName,project)if (id != 0){gitlabProjectIds.add(id)}}return gitlabProjectIds
}// 根据项目名称获取项目iddef GetProjectId(groupName,projectName){apiUrl = "projects?search=${projectName}"response =  HttpReq('GET', apiUrl, "")response =  readJSON text: response.content - "\n"if (response.size() > 1){for (i in response){if (i["path_with_namespace"] == "${groupName}/${projectName}"){return i["id"]}}}else {return  response[0]["id"]}}// 封装HTTP
def HttpReq(reqType, reqUrl,reqBody ){def gitServer = "http://192.168.204.8:82/api/v4"withCredentials([string(credentialsId: '02dce3ff-4e46-4de2-b079-5dd6093d4f64', variable: 'GITLABTOKEN')]) {response = httpRequest acceptType: 'APPLICATION_JSON_UTF8',consoleLogResponseBody: true,contentType: 'APPLICATION_JSON_UTF8',customHeaders: [[maskValue: false, name: 'PRIVATE-TOKEN', value: "${GITLABTOKEN}"]],httpMode: "${reqType}",url: "${gitServer}/${reqUrl}",wrapAsMultipart: false,requestBody: "${reqBody}"}return response
}

保存

4.K8S master节点操作

(1)K8S master节点另开一个终端用watch命令观察pod变化

# watch -n 1 "kubectl get pod -n devops03"

(2)外部测试访问

# curl http://devops03-devops-ui.devops.com:31291

(3)删除命名空间devops03

# kubectl delete ns devops03

(4)观察pod变化

5.Jira 发布流水线

(1)Jira新建问题

(2)Jira创建事件触发Jenkins流水线

(3) GitLab更新特性分支DEVOPS-11


(4)修改GitLab修改特性分支Dockerfile,并提交特性分支DEVOPS3-11


(5)Jira 新建版本

(6)查看版本

(7)修改版本为1.1.11

(8)Jenkins更新事件触发Jenkins流水线

(9)GitLab提示特性分支合并到版本分支的请求

(10)合并请求

(11)完成合并

(12)查看合并

(13)Jenkins构建基于HELM的K8S CI流水线

(14)成功

(15)查看Blue Ocean

(16) 查看阶段视图

(17)Harbor查看镜像

192.168.204.15/devops03/devops03-devops-ui:RELEASE-1.1.11

(18)K8S node节点连接Harbor拉取镜像

# docker login -u admin -p Harbor12345 192.168.204.15# docker pull 192.168.204.15/devops03/devops03-devops-ui:RELEASE-1.1.11# docker logout 192.168.204.15

node1节点

node2节点

(19)K8S master节点创建命名空间devops03,目前无资源

#  kubectl create ns devops03#  kubectl get all -n devops03

(20)GitLab 查看HELM模板文件values.yaml 已更新镜像标签为RELEASE-1.1.11

(21)Jenkins构建基于HELM的K8S CD流水线

(22)观察pod变化

(23)外部测试访问(当前版本为1.1.11)

# curl http://devops03-devops-ui.devops.com:31291

(24)最后版本分支 RELEASE-1.1.11 合并到master分支

http://www.lryc.cn/news/267315.html

相关文章:

  • JuiceSSH结合内网穿透实现公网远程访问本地Linux虚拟机
  • 使用 pytest.ini 文件控制输出 log 日志
  • 【Spring】SpringBoot 配置文件
  • Koordinator 支持 K8s 与 YARN 混部,小红书在离线混部实践分享
  • 网游逆向分析与插件开发-游戏反调试功能的实现-项目需求与需求拆解
  • 阶段七-GitEE
  • Redis小记(1)
  • Flutter windows 环境配置
  • odoo17核心概念view5——ir_ui_view.py
  • 截断整型提升算数转换
  • 阿里云 ECS Docker、Docker Compose安装
  • LeetCode——1276. 不浪费原料的汉堡制作方案
  • 隆道吴树贵:生成式人工智能在招标采购中的应用
  • docker搭建kali及安装oneforall
  • 【MySQL】数据库之事务
  • AGV|RGV小车RFID传感器CNS-RFID-01/1S的RS232通讯联机方法
  • 【Python可视化系列】一文教会你绘制美观的热力图(理论+源码)
  • 百度Apollo五步入门自动驾驶:Dreamview与离线数据包分析(文末赠送apollo周边)
  • 为什么IPv6 可以作为低功耗蓝牙的物联网体系结构?
  • GPT每预测一个token就要调用一次模型
  • 运维工程师的出路到底在哪里?
  • 2312clang,基于访问者的前端动作
  • 怎么搭建实时渲染云传输服务器
  • 如何在生产环境正确使用Redis
  • LeetCode-环形链表问题
  • C# 读取Word表格到DataSet
  • 构建外卖系统:从技术到实战
  • 城市之眼:数据可视化在智慧城市的角色
  • Nature | Baker团队用AI设计出史上最高互作强度的蛋白质
  • C# 初识System.IO.Pipelines