Sfoglia il codice sorgente

feature: 添加Jenkinsfile文件

huangjy 4 anni fa
parent
commit
fea54ef45c
1 ha cambiato i file con 74 aggiunte e 0 eliminazioni
  1. 74 0
      Jenkinsfile

+ 74 - 0
Jenkinsfile

@@ -0,0 +1,74 @@
+#!groovy
+@Library('jenkinslib') _
+
+def build = new org.devops.build()
+def color = new org.devops.color()
+
+def String cpu = "${env.cpu}"
+def String imagePrefix = "${env.imagePrefix}"
+
+pipeline {
+    agent {
+        node {
+            label 'master'
+        }
+    }
+    options {
+        disableConcurrentBuilds()
+        buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '20')
+    }
+
+    //设定2个参数,根据项目类型不同,修改对应的description name value visibleItemCount  defaultValue 即可
+    parameters {
+        extendedChoice description: '请选择CPU架构.可单选/多选/全选', multiSelectDelimiter: ',', name: 'cpu',
+                       quoteValue: true,
+                       saveJSONParameterToFile: false,
+                       type: 'PT_CHECKBOX',
+                       value: 'x86,arm64',
+                       visibleItemCount: 5
+        string defaultValue: 'bus.ga/jzywb/approve/approve-gateway-service/', description: '请填写打的镜像通用前缀名称,注意最后面要加 / ', name: 'imagePrefix', trim: false
+    }
+    stages{
+        stage('MAVEN-BUILD') {
+            steps {
+                script {
+                    color.PrintMes('执行mvn打包','green')
+                    //使用mvn方法打包,并传入打包参数.根据实际情况修改打包策略
+                    build.Build('mvn','mvn clean package -DskipTests=true','master')
+                }
+            }
+        }
+        stage('DOCKER-BUILD') {
+            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"
+                }
+            }
+        }
+    }
+}