#!groovy library 'sre-shared-library' pipeline { agent any parameters { //repoBranch参数 string(name:'repoBranch', defaultValue: 'master', description: 'git分支名称') //服务器选择 choice(name: 'server',choices:'192.168.1.107,9090\n192.168.1.60,9090', description: '测试服务器列表选择(IP,JettyPort,Name,Passwd)') string(name:'dubboPort', defaultValue: '31100', description: '测试服务器的dubbo服务端口') //单元测试代码覆盖率要求,各项目视要求调整参数 string(name:'lineCoverage', defaultValue: '20', description: '单元测试代码覆盖率要求(%),小于此值pipeline将会失败!') //若勾选在pipelie完成后会邮件通知测试人员进行验收 booleanParam(name: 'isCommitQA',description: '是否在pipeline完成后,邮件通知测试人员进行人工验收',defaultValue: false ) } //环境变量,初始确定后一般不需更改 //tools { // maven 'maven3' // jdk 'jdk8' //} stages { stage('email'){ sh echo "测试发送邮件" // 设置生成模板文件 configFileProvider([configFile(fileId: ' Extended-Email-Publisher', targetLocation: 'email.html', variable: 'failt_email_template')]) { // 读取模板 template = readFile encoding: 'UTF-8', file: "${failt_email_template}" // 发送邮件 emailext(subject: '任务执行失败', attachLog: true, recipientProviders: [requestor()], to: '32*****47@qq.com', body: """${template}""") } } stage('Build') { steps { sh 'echo "Hello World"' // sh 'CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o exporter main.go' } } stage('Test') { steps { /* `make check` returns non-zero on test failures, * using `true` to allow the Pipeline to continue nonetheless */ sh 'ls' } } stage('Deploy') { when { expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' //访问该currentBuild.result变量允许Pipeline确定是否有任何测试失败。在这种情况下,值将是 UNSTABLE。 } } steps { sh 'echo ok' } } //部署可能意味着各种步骤,具体取决于项目或组织的要求,并且可能是从构建的工件发送到Artifactory服务器,将代码推送到生产系统的任何步骤。 //在Pipeline示例的这个阶段,“构建”和“测试”阶段都已成功执行。实际上,“部署”阶段只能在上一阶段成功完成,否则Pipeline将早退。 } }