Explorar o código

Merge branch 'jenkins' of http://git.dayaedu.com/molingzhide/daya-mall-admin into jenkins

lex %!s(int64=2) %!d(string=hai) anos
pai
achega
bfa8a522c1
Modificáronse 3 ficheiros con 87 adicións e 0 borrados
  1. 1 0
      .gitignore
  2. 84 0
      Jenkinsfile
  3. 2 0
      build/build.js

+ 1 - 0
.gitignore

@@ -1,5 +1,6 @@
 .DS_Store
 node_modules/
+dist/
 npm-debug.log*
 yarn-debug.log*
 yarn-error.log*

+ 84 - 0
Jenkinsfile

@@ -0,0 +1,84 @@
+pipeline {
+    agent any
+
+    environment {
+       BUILD_USER = ""
+       REMOTE_PATH = "/mnt/datadisk/www/daya-mall-admin"
+       BUILD_FILE = "dist.tar.gz"
+       ROBOT_ID = "a346e21b-706e-4881-8e3b-6c48d16d0c3b"
+       SSH_AUTH = "ECS-Daya-47.114.176.40-dev"
+    }
+
+    stages {
+        
+        stage('build param') {
+            steps {
+                wrap([$class: 'BuildUser']) {
+                    script {
+                        BUILD_USER = "${env.BUILD_USER}"
+                    }           
+                }
+                echo '${BUILD_USER}'
+            }
+        }
+
+        stage('build job') {
+            steps {
+                sh 'node -v'
+                sh 'npm install && npm run build'
+                sh "tar -zcf ${BUILD_FILE} dist/"
+            }
+        }
+
+        stage('deploy job') {
+            steps {
+                sshPublisher(publishers: [sshPublisherDesc(configName: "${SSH_AUTH}", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "cd ${REMOTE_PATH} && rm -rf dist/ && tar -zxf *.tar.gz && rm *.tar.gz", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: "${REMOTE_PATH}", remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/*.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
+            }
+        }
+
+        stage('clean job') {
+            steps {
+                sh "rm ${BUILD_FILE}"
+            }
+        }
+    }
+
+    post {
+        
+        success {
+            dingtalk (
+                robot: "${ROBOT_ID}",
+                type:'ACTION_CARD',
+                atAll: false,
+                title: "构建成功:${env.JOB_NAME}",
+                //messageUrl: 'xxxx',
+                text: [
+                    "### [${env.JOB_NAME}](${env.JOB_URL}) ",
+                    '---',
+                    "- 任务:[${currentBuild.displayName}](${env.BUILD_URL})",
+                    '- 状态:<font color=#00CD00 >成功</font>',
+                    "- 持续时间:${currentBuild.durationString}".split("and counting")[0],
+                    "- 执行人:${BUILD_USER}",
+                ]
+            )
+        }
+
+        failure{
+            dingtalk (
+                robot: "${ROBOT_ID}",
+                type:'ACTION_CARD',
+                atAll: false,
+                title: "构建失败:${env.JOB_NAME}",
+                //messageUrl: 'xxxx',
+                text: [
+                    "### [${env.JOB_NAME}](${env.JOB_URL}) ",
+                    '---',
+                    "- 任务:[${currentBuild.displayName}](${env.BUILD_URL})",
+                    '- 状态:<font color=#EE0000 >失败</font>',
+                    "- 持续时间:${currentBuild.durationString}".split("and counting")[0],
+                    "- 执行人:${BUILD_USER}",
+                ]
+            )
+        }
+    }
+}

+ 2 - 0
build/build.js

@@ -37,5 +37,7 @@ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
       '  Tip: built files are meant to be served over an HTTP server.\n' +
       '  Opening index.html over file:// won\'t work.\n'
     ))
+    
+    process.exit(0)
   })
 })