1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #!groovy
- @Library('jenkinslib') _
- def build = new org.devops.build()
- def color = new org.devops.color()
- def systemtime = new org.devops.systemtime()
- def String cpu = "${env.cpu}"
- def String imagePrefix = "${env.imagePrefix}"
- def String buildImage = "${env.buildImage}"
- pipeline {
- agent {
- node {
- label 'master'
- }
- }
- options {
- disableConcurrentBuilds()
- buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '20')
- }
- //设定2个参数,根据项目类型不同,修改对应的description name value visibleItemCount defaultValue 即可
- parameters {
- choice choices: ['false', 'true'], description: '是否需要打镜像包,默认为否', name: 'buildImage'
- extendedChoice description: '只有在需要打镜像包的情况下,才需要选择CPU架构。可单选/多选/全选', multiSelectDelimiter: ',', name: 'cpu',
- quoteValue: true,
- saveJSONParameterToFile: false,
- type: 'PT_CHECKBOX',
- value: 'x86,arm64',
- visibleItemCount: 5
- // 需修改对应的镜像名称
- string defaultValue: 'bus.ga/jzywb/dcuc/', description: '只有在需要打镜像包的情况下,才需要填写要打镜像通用前缀名称,注意最后面要加 / ', name: 'imagePrefix', trim: false
- }
- stages {
- stage('MAVEN-BUILD') {
- steps {
- script {
- color.PrintMes('执行mvn打包', 'green')
- //使用mvn方法打包,并传入打包参数.根据实际情况修改打包策略
- build.Build('mvn', 'mvn clean deploy -DskipTests=true', 'master')
- }
- }
- post {
- success {
- script {
- version = build.GetMvnParentVersion()
- systime = systemtime.GetSysTime('yyMMdd')
- //将打出来的tar包,按照命名规范命名。根据实际情况,修改对应的系统简称和区域标识(DCUC-DUCEAP-SERVICE-TJDSJ)
- sh """cd dcuc-duceap-service/target
- cp dcuc-duceap-service-*.tar.gz DCUC-DUCEAP-SERVICE-TJDSJ-${version}-${env.GIT_COMMIT.take(8)}-BETA-${systime}.tar.gz
- """
- //将复制的按照命名规范的tar包提取到Jenkins的面板,方便下载。根据实际情况,修改对应的系统简称和区域标识(DCUC-DUCEAP-SERVICE-TJDSJ)
- archiveArtifacts artifacts: 'dcuc-duceap-service/target/DCUC-DUCEAP-SERVICE-TJDSJ-*.tar.gz'
- }
- }
- }
- }
- stage('DOCKER-BUILD') {
- when {
- expression {
- return (buildImage == 'true')
- }
- }
- steps {
- script {
- //将cpu架构和模块名称传入方法打镜像包.若在上面定义的参数名称没变,可不修改
- build.BuildImage("${cpu}")
- }
- }
- }
- }
- //构建后的操作,用来显示结果.所有项目都适用,可不改
- post {
- success {
- wrap([$class: 'BuildUser']) {
- script {
- currentBuild.description = "Start By ${env.BUILD_USER} And Build Success"
- }
- }
- }
- failure {
- wrap([$class: 'BuildUser']) {
- script {
- currentBuild.description = "Start By ${env.BUILD_USER} And Build Failure"
- }
- }
- }
- unstable {
- wrap([$class: 'BuildUser']) {
- script {
- currentBuild.description = "Start By ${env.BUILD_USER} And Build Unstable"
- }
- }
- }
- }
- }
|