一. Jira简介
中文官网:https://www.atlassian.com/zh/software/jira
1.1 Jira可以做什么?
规划
创建项目,用户需求和事务、规划 Sprint 并跨团队分配开发任务。
跟踪
全面了解项目进度情况,安排整个团队工作的优先级排序并进行讨论。
二. 安装部署
2.1 数据中心版本
https://www.atlassian.com/zh/software/jira/pricing?tab=data-center 试用
选择历史版本下载:
下载最新的LTS 长期支持版本:
选择部署的环境:
开始下载Jira Software Server安装程序:
2.2 安装部署
scpatlassian-jira-software-8.20.1-x64.binroot@192.168.1.200:/opt/ ##添加权限 [root@zeyang-nuc-serviceopt]#chmod+xatlassian-jira-software-8.20.1-x64.bin ##运行安装程序 [root@zeyang-nuc-serviceopt]#./atlassian-jira-software-8.20.1-x64.bin UnpackingJRE... StartingInstaller... ThiswillinstallJiraSoftware8.20.1onyourcomputer. OK[o,Enter],Cancel[c]##回车 ClickNexttocontinue,orCanceltoexitSetup. Choosetheappropriateinstallationorupgradeoption. Pleasechooseoneofthefollowing: ExpressInstall(usedefaultsettings)[1],CustomInstall(recommendedforadvancedusers)[2,Enter],UpgradeanexistingJirainstallation[3] ##此处选择自定义安装,输入回车 SelectthefolderwhereyouwouldlikeJiraSoftwaretobeinstalled. WhereshouldJiraSoftwarebeinstalled? [/opt/atlassian/jira] ##选择安装目录 DefaultlocationforJiraSoftwaredata [/var/atlassian/application-data/jira] ##选择数据目录 ConfigurewhichportsJiraSoftwarewilluse. JirarequirestwoTCPportsthatarenotbeingusedbyanyother applicationsonthismachine.TheHTTPportiswhereyouwillaccessJira throughyourbrowser.TheControlportisusedtostartupandshutdownJira. Usedefaultports(HTTP:8080,Control:8005)-Recommended[1,Enter],SetcustomvalueforHTTPandControlports[2] 2##输入2自定义服务端口 HTTPPortNumber [8071] 8801 ControlPortNumber [8077] 8802 ##安装服务 Jiracanberuninthebackground. YoumaychoosetorunJiraasaservice,whichmeansitwillstart automaticallywheneverthecomputerrestarts. InstallJiraasService? Yes[y,Enter],No[n] y DetailsonwhereJiraSoftwarewillbeinstalledandthesettingsthatwillbeused. InstallationDirectory:/opt/atlassian/jira HomeDirectory:/var/atlassian/application-data/jira HTTPPort:8801 RMIPort:8802 Installasservice:Yes Install[i,Enter],Exit[e] Extractingfiles... ##启动服务 PleasewaitafewmomentswhileJiraSoftwareisconfigured. InstallationofJiraSoftware8.20.1iscomplete StartJiraSoftware8.20.1now? Yes[y,Enter],No[n] y PleasewaitafewmomentswhileJiraSoftwarestartsup. LaunchingJiraSoftware... InstallationofJiraSoftware8.20.1iscomplete YourinstallationofJiraSoftware8.20.1isnowreadyandcanbeaccessed viayourbrowser. JiraSoftware8.20.1canbeaccessedathttp://localhost:8801 Finishinginstallation...
访问:http://serverip:8801
2.3 初始化配置
获取授权码:
注册账号登录:生成授权码,激活实例;
三. Jira使用实践
3.1 创建一个项目
注意:一个Jira 项目对应一个GitLab项目组;
3.2 为项目添加模块
注意:一个Jira模块对应一个GitLab项目;
3.3 配置WebHook系统, 网络钩子(webhook)
3.4 需求/任务管理
创建需求
这里在Jira上面把这个需求logging-error, 类型为故事 关联到devops03-devops-service模块;
3.5 发布Release
课程中把 发布对应为GitLab项目代码库中的版本分支;
issue关联发布:可以想象成GitLab特性分支合并到版本分支;
四. Jira自动化实践
工作流
工具链集成
4.1 需求与代码关联
1. 创建Jenkins作业并配置webhook
webhookData:这个变量存放的是Jira 传递的数据。
2. 为Jira配置一个系统级别的webhook
选项解释:
- 指定Jenkins的webhook触发器地址;
- 通过JQL指定,允许devops03这个项目进行触发;
- 勾选动作,触发事件;(我在jira做了什么操作之后能够触发)
3. Jenkins流水线配置
解析Jira传递过来的数据;
webhookData=readJSONtext:"${webhookData}" //Jira事件 jiraEvent=webhookData.webhookEvent jiraProjectName=webhookData.issue.fields.project.name //获取gitlab参数 gitlabProjects=[] gitlabBranchName=webhookData.issue.key gitlabGroupName=jiraProjectName for(iinwebhookData.issue.fields.components){ gitlabProjects.add(i["name"]) } currentBuild.description="Triggerby${jiraEvent}\nproject:${gitlabProjects}\nbranch:${gitlabBranchName}"
封装GitLab API接口
https://docs.gitlab.com/ee/api/branches.html#create-repository-branch
//创建分支 defCreateBranch(projectId,newBranchName,sourceBranchName){ try{ apiUrl="projects/${projectId}/repository/branches?branch=${newBranchName}&ref=${sourceBranchName}" response=HttpReq('POST',apiUrl,"") } catch(Exceptione){ println(e) } } //获取所有项目的id defGetProjectsId(gitlabGroupName,gitlabProjects){ gitlabProjectIds=[] for(projectingitlabProjects){ id=GetProjectId(gitlabGroupName,project) println(id) if(id!=0){ gitlabProjectIds.add(id) } } returngitlabProjectIds } //根据项目名称获取项目id defGetProjectId(groupName,projectName){ apiUrl="projects?search=${projectName}" response=HttpReq('GET',apiUrl,"") response=readJSONtext:response.content-"\n" if(response.size()>1){ for(iinresponse){ println(i["path_with_namespace"]) println(groupName+projectName) if(i["path_with_namespace"]=="${groupName}/${projectName}"){ println(i["id"]) returni["id"] } } }else{ returnresponse[0]["id"] } } //封装HTTP defHttpReq(reqType,reqUrl,reqBody){ defgitServer="http://192.168.1.200/api/v4" withCredentials([string(credentialsId:'058b7907-ebe2-4d14-9b91-1ac72e071c59',variable:'GITLABTOKEN')]){ response=httpRequestacceptType:'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}" } returnresponse }
Pipeline主程序
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(idinprojectIds){ CreateBranch(id,gitlabBranchName,"master") } break default: println("error...") break } } } } } }
4. 效果验证
在Jira里面创建一个模块和issue, 关联项目;
Jenkins 流水线运行;
验证Gitlab中多了分支;
转载请注明:IT运维空间 » 运维技术 » Jira自动化实践:基于Jenkins实现需求与代码基线关联
发表评论