You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
5.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//Jenkins配置流水线时应该将默认Jenkinsfile改为Jenkinsfile127
//修改cstatm211601,可批量替换
pipeline {
agent any
options {
//跳过从源代码控制中检出代码使用阶段stage('拉取Gitea源码')
skipDefaultCheckout(true)
}
stages {
stage('拉取Gitea源码') {
steps {
cleanWs()//清除Jenkins的工作区WorkSpace
//gitea为Jenkins中的凭据:用访问gitea的账号、密码生成
//修改2018211601自己的学号
git credentialsId: 'gitea', url: 'http://localhost:3000/2018211601/cstatm211601.git'
}
}
stage('Maven Sonar 打包') {
steps {
//SonarQube为Jenkins系统中配置的服务器名称并设置SonarQube口令
withSonarQubeEnv('SonarQube'){
//Maven使用SonarQube进行源码扫描
//-D为SonarQube扫描属性
//127上的口令-Dsonar.token=SonarQube登录、账号、安全、通用口令生成复制
bat '''mvn clean package sonar:sonar -Dsonar.projectKey=cstatm211601
-Dsonar.projectName=cstatm211601 -Dsonar.java.binaries=. -Dsonar.skipPackageDesign=true
-Dsonar.token=squ_d7d970c7b6c36fe2b3b7bc3ccea60239f8028878'''
}
}
}
stage('QualityGate质量门禁') {
steps {
script{
sleep(30)//休眠30秒等待扫描结果返回质量门禁获取数据
//超时10分钟等待足够时间避免质量门禁失败
timeout(time: 10, unit: 'MINUTES'){
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "流水线由于门禁失败而退出: ${qg.status}"
}
}
}
}
}
//JDK的各个工具参数可查阅命令行如keytool /
stage('keytool生成密钥'){
steps{
// liudongliang 改为自己姓名拼音
//keytool很长但不能换行
bat '''
keytool -genkey -alias mykey -keystore mykeystore.store -storetype PKCS12 -keyalg RSA -storepass mystorepass -validity 365 -keysize 2048 -dname "CN=liudongliang, OU=chzu, L=xxxy, S=chuzhou, O=anhui, C=CH"
'''
}
}
stage('jarsigner数字签名') {
steps {
bat '''
MKDIR app
MOVE /Y "target\\cstatm211601-0.0.1-SNAPSHOT-jar-with-dependencies.jar" "app\\cstatm211601.jar"
jarsigner -keystore myKeystore.store app\\cstatm211601.jar mykey -storepass mystorepass
'''
}
}
stage('jpackage生成msi'){
steps{
//必须安装、配置WixTools
//修改主类名com.atm.view.gui.Gui
bat '''
jpackage -i ./app --type msi -n cstatm211601_msi --main-jar cstatm211601.jar --main-class com.atm.view.gui.Gui --vendor dll --verbose --win-console --win-dir-chooser --win-shortcut --win-menu
'''
}
post {
success {
//Jenkins制品
archiveArtifacts 'cstatm211601_msi-1.0.msi'
}
}
}
stage('jar打包War(jar&msi)') {
steps {
bat 'jar cfM cstatm211601.war index.html cstatm211601.jnlp ./app/cstatm211601.jar cstatm211601_msi-1.0.msi'
}
}
//部署tomcat9为部署的Web服务器选项最新tomcat9而实际服务器为tomcat10
//'tomcat'为Jenkins凭据id,访问tomcat,必须为管理员权限
stage('部署War至local127tomcat'){
steps{
deploy adapters: [tomcat9(credentialsId: 'tomcat', path: '', url: 'http://localhost:8080')], contextPath: '/cstatm211601', war: 'cstatm211601.war'
}
}
stage('local127访问cstatm211601'){
steps{
echo "explorer http://localhost:8080/cstatm211601/index.html"
}
}
//试看谁第一个发邮件给我?
stage("通知邮件") {
steps{
script {
mail to: '602924803@qq.com',
subject: "软件流水线: ${currentBuild.fullDisplayName}",
body: " ${env.JOB_NAME}-构建#${env.BUILD_ID}-状态#${currentBuild.currentResult}\n 控制台 ${BUILD_URL} 查看结果。"
}
}
}
}
post {
always {
//清理工作区函数
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true,
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
}
}
}