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.

112 lines
4.6 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.

pipeline {
agent any
options {
// 跳过默认检出,使用自定义拉取源码阶段
skipDefaultCheckout(true)
}
stages {
stage('拉取Gitea源码') {
steps {
cleanWs() // 清除Jenkins工作区
// 核心修改连接你的目标Gitea仓库保留凭据ID"gitea"(需提前配置)
git credentialsId: 'gitea', url: 'http://localhost:3000/lrx/cstatm23210465'
}
}
stage('Maven Sonar 打包') {
steps {
// SonarQube为Jenkins配置的服务器名称token沿用原配置需确认有效性
withSonarQubeEnv('SonarQube'){
bat '''mvn clean package sonar:sonar -Dsonar.projectKey=cstatm23210465
-Dsonar.projectName=cstatm23210465 -Dsonar.java.binaries=. -Dsonar.skipPackageDesign=true
-Dsonar.token=squ_d7d970c7b6c36fe2b3b7bc3ccea60239f8028878'''
}
}
}
stage('QualityGate质量门禁') {
steps {
script{
sleep(30) // 休眠30秒等待扫描结果返回
timeout(time: 10, unit: 'MINUTES'){ // 超时10分钟容错
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "流水线由于门禁失败而退出: ${qg.status}"
}
}
}
}
}
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 {
// 路径同步项目名双反斜杠确保Windows环境无语法错误
bat '''MKDIR app
MOVE /Y "target\\cstatm23210465-0.0.1-SNAPSHOT-jar-with-dependencies.jar" "app\\cstatm23210465.jar"
jarsigner -keystore myKeystore.store app\\cstatm23210465.jar mykey -storepass mystorepass'''
}
}
stage('jpackage生成msi'){
steps{
// 提示必须安装配置WixTools主类名com.atm.view.gui.Gui需按实际项目修改
bat '''jpackage -i ./app --type msi -n cstatm23210465_msi --main-jar cstatm23210465.jar --main-class com.atm.view.gui.Gui --vendor dll --verbose --win-console --win-dir-chooser --win-shortcut --win-menu'''
}
post {
success {
// 归档msi制品文件名同步项目名
archiveArtifacts 'cstatm23210465_msi-1.0.msi'
}
}
}
stage('jar打包War(jar&msi)') {
steps {
// 批量替换项目名同步jnlp、jar、msi文件名
bat 'jar cfM cstatm23210465.war index.html cstatm23210465.jnlp ./app/cstatm23210465.jar cstatm23210465_msi-1.0.msi'
}
}
stage('部署War至local127tomcat'){
steps{
// 部署路径、war包名同步项目名凭据ID"tomcat"需配置Tomcat管理员账号密码
deploy adapters: [tomcat9(credentialsId: 'tomcat', path: '', url: 'http://localhost:8080')], contextPath: '/cstatm23210465', war: 'cstatm23210465.war'
}
}
stage('local127访问cstatm23210465'){
steps{
echo "explorer http://localhost:8080/cstatm23210465/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 {
// 清理工作区(保留.gitignore排除.propsfile
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true,
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
}
}
}