pipeline 质量门禁+邮件发送
import hudson.model.*;
println env.JOB_NAME
println env.BUILD_NUMBER
println env.WORKSPACE
pipeline {
agent {
label 'master'
}
stages {
stage("Quality access control") {
steps {
timeout(time: 1, unit: 'MINUTES') {
script {
env.CHECK = input message: '是否使用质量门禁', ok: '确定',
parameters: [choice(name: 'CHECK', choices: ['yes', 'no'], description: '是否使用质量门禁')]
switch("${env.CHECK}"){
case 'yes':
sh '''
echo '执行python脚本'
'''
break;
case 'no':
sh '''
echo '跳过质量门禁'
'''
break;
default:
sh '''
echo '执行python脚本'
'''
break;
}
}
}
}
}
stage('svn checkout code') {
steps {
checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'd8147deb-bc71-426a-a332-155125f185d1', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'http://172.16.6.16/svn/Q1_51Yun_Core/trunk/sourcecode/ZZS_DZFP_51SAAS/51SAAS_CXDDLB/51openapi/open-Api/branches']], quietOperation: true, workspaceUpdater: [$class: 'CheckoutUpdater']])
}
}
stage('sonar') {
steps {
sh '''
/opt/sonar-scanner/bin/sonar-scanner -X -Dsonar.host.url="http://172.16.6.136:55555" \
-Dsonar.projectKey=CTest_J_JS_OpenApi \
-Dsonar.projectName=CTest_J_JS_OpenApi \
-Dsonar.projectVersion=${BUILD_NUMBER} \
-Dsonar.sources=2021-06-04(2021-05-18版本的测试环境配置)/trunk/commonUtil/src/main/java \
-Dsonar.login=JZB_upload \
-Dsonar.password=aisino123 \
-Dsonar.java.binaries=${WORKSPACE} \
-Dsonar.java.source=1.8 \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.language=java \
-Dsonar.scm.disabled=true
'''
}
}
stage('mvn build') {
steps {
sh '''
###############################################################################
############################## 修改编译 ##################################
###############################################################################
#cd /usr/java/jenkins/.jenkins/jobs/Dev-openapi/jobs/test-openapi-token-verify/workspace/2021-06-04(2021-05-18版本的测试环境配置)/trunk
/usr/local/apache-maven-3.6.1/bin/mvn -f 2021-06-04(2021-05-18版本的测试环境配置)/trunk/pom.xml clean package -U -Dmaven.test.skip=true
'''
}
}
stage('复制到临时制品库') {
steps {
sh '''
cp -r 2021-06-04(2021-05-18版本的测试环境配置)/trunk/token-verify/target/*.war /usr/java/jenkins/.jenkins/tempArtifact/Dev-openapi/test-openapi-token-verify/
'''
}
}
stage('发布到服务器') {
steps {
sh '''
scp -P26622 -r /usr/java/jenkins/.jenkins/tempArtifact/Dev-openapi/test-openapi-token-verify/*.war tomcat_openapi@192.168.15.241:/home/tomcat_openapi/update
'''
}
}
stage('启动服务') {
steps {
sh '''
echo "启动成功"
#ssh -p 26622 tomcat_openapi@192.168.15.241 "sh /home/tomcat_openapi/update/update-token-verify.sh"
'''
}
}
}
post {
always {
echo '构建结束...'
echo 'clean workspace'
deleteDir()
}
success {
echo '恭喜您,构建成功!!!'
mail subject: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' 执行成功",
body: """
<div id="content">
<h2><font color="#0B610B">构建信息</font></h2>
<hr size="2" width="100%" align="center" />
<div id="sum2">
<h2>Jenkins 运行结果</h2>
<ul>
<li>构建结果:\t<font color="#CC0000">jenkins 构建成功</font></li>
<li>项目名称:\t<a>${env.JOB_NAME}</a></li>
<li>构建次数:\t<a">第${env.BUILD_NUMBER}次构建</a></li>
<li>构建 URL:\t<a href='${env.BUILD_URL}'>${env.BUILD_URL}</a></li>
<li>构建日志:\t<a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
<li>质量门禁:\t<a>http://172.16.6.22:8080/jenkins/job/qualitycheck/job/fws-bj-test-qualitycheck-jenkins</a></li>
</ul>
</div>
</div>
""",
charset: 'utf-8',
from: 'fengjian21@aisino.com',
mimeType: 'text/html',
to: "17601624836@163.com,fengjian21@aisino.com"
}
failure {
echo '抱歉,构建失败!!!'
mail subject: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' 执行失败",
body: """
<div id="content">
<h2><font color="#0B610B">构建信息</font></h2>
<hr size="2" width="100%" align="center" />
<div id="sum2">
<h2>Jenkins 运行结果</h2>
<ul>
<li>构建结果:\t<font color="#CC0000"> 构建失败</font></li>
<li>项目名称:\t<a>${env.JOB_NAME}</a></li>
<li>构建次数:\t<a>第${env.BUILD_NUMBER}次构建</a></li>
<li>构建 URL:\t<a href='${env.BUILD_URL}'>${env.BUILD_URL}</a></li>
<li>构建日志:\t<a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
<li>质量门禁:\t<a>http://172.16.6.22:8080/jenkins/job/qualitycheck/job/fws-bj-test-qualitycheck-jenkins</a></li>
</ul>
</div>
</div>
""",
charset: 'utf-8',
from: 'fengjian21@aisino.com',
mimeType: 'text/html',
to: "17601624836@163.com,fengjian21@aisino.com"
}
unstable {
echo '该任务已经被标记为不稳定任务....'
}
changed {
echo ''
}
}
}