jira 网络钩子 链接:https://developer.atlassian.com/server/jira/platform/webhooks/
jira REST API链接 : https://docs.atlassian.com/software/jira/docs/api/REST/8.5.12/
gitlab API 链接: https://docs.gitlab.com/ce/api/
URL编码表 链接 https://www.runoob.com/tags/html-urlencode.html
ant 批量执行 jmeter的xxx.jmx脚本 ant和jmeter集成小细节:jmeter/extras/ant-jmeter-1.1.1.jar需复制一份到ant/lib/
UAT测试流水线示例:
UATjenkinsfile:
#!groovy @Library('jenkinslibrary') _ def too = new org.devops.tools() def sonar = new org.devops.sonarqube() def sonarapi = new org.devops.sonarapi() def toemail = new org.devops.toemail() def nexus = new org.devops.nexus() pipeline{ agent any tools { maven 'maven3.6.3' ant 'ant1.10.9' } triggers { GenericTrigger ( causeString: 'Generic Cause', genericVariables: [ [defaultValue: '', key: 'webhook', regexpFilter: '', value: '$'], [defaultValue: '', key: 'state', regexpFilter: '', value: '$.object_attributes.state'] ], printContributedVariables: true, printPostContent: true, regexpFilterExpression: 'merged', regexpFilterText: '$state', token: 'gitlab' ) } stages{ stage("拉代码"){ steps{ script{ currentBuild.description = "从${webhook_object_attributes_source_branch}分支合并到${webhook_object_attributes_target_branch}分支触发" too.PrintMes("拉取代码","green") checkout( [$class: 'GitSCM', branches: [[name: '*/${webhook_object_attributes_target_branch}']], userRemoteConfigs: [[credentialsId: 'gitlab-root', url: '${webhook_object_attributes_target_http_url}']]] ) } } } stage("编译单测"){ steps{ sh "mvn clean test" junit 'target/surefire-reports/*.xml' } } stage('代码质量') { steps{ script{ too.PrintMes("搜索项目","green") result = sonarapi.SerarchProject("${webhook_object_attributes_target_name}") if (result == "false"){ println("${webhook_object_attributes_target_name}---项目不存在,准备创建项目---> ${webhook_object_attributes_target_name}!") sonarapi.CreateProject("${webhook_object_attributes_target_name}") } else { println("${webhook_object_attributes_target_name}---项目已存在!") } too.PrintMes("代码扫描","green") sonar.SonarScan("test","${webhook_object_attributes_target_name}","${webhook_object_attributes_target_name}","src") sleep 30 //等待刷新扫描结果时间,不等待的话可能新结果还没刷新,获取的是上一次的结果 too.PrintMes("获取扫描结果","green") result = sonarapi.GetProjectStatus("${webhook_object_attributes_target_name}") if (result.toString() == "ERROR"){ //判断质量阈状态是错误则发送邮件并中断构建 toemail.Email("代码质量阈错误!请及时修复!","${webhook_object_attributes_last_commit_author_email}") error " 代码质量阈错误!请及时修复!" } else { println(result) } } } } stage("打包,上传制品"){ steps{ script{ sh "mvn -Dmaven.test.skip=true package" //nexus.main("nexus") 实在没太多资源再开多个nexus私服了就先注释掉了 } } } stage("构建镜像/推送仓库"){ steps{ script{ //sh "docker build -t test:v1 . && docerk push test:v1" //这个只是示例,具体标签肯定要有规划的,推送到镜像仓库了。nexus私服做镜像仓库,nexus没开所以只是简单示例 sh "docker build -t test:v1 ." } } } stage("发布"){ steps{ script{//使用插件连接远程服务器执行kubectl命令。这里先暂时运行个Pod.要是deployments之类的就先上传文件,问题不大 sshPublisher(publishers: [sshPublisherDesc(configName: 'k8s', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'kubectl run test --image=test:v1', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)]) } } } stage("接口测试"){ steps{ script{ sh "ant -f build.xml" publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'result/htmlfile', reportFiles: 'SummaryReport.html,DetailReport.html', reportName: 'InterfaceTestReport', reportTitles: '']) } } } } post { always{ script{ println("always") } } success{ script{ println("success") toemail.Email("流水线成功","${webhook_object_attributes_last_commit_author_email}") } } failure{ script{ println("failure") toemail.Email("流水线失败了!","${webhook_object_attributes_last_commit_author_email}") } } aborted{ script{ println("aborted") toemail.Email("流水线被取消了!","${webhook_object_attributes_last_commit_author_email}") } } } }