Browse Source

增加Jenkins构建文件

shangke 2 years ago
parent
commit
67980036a3
1 changed files with 80 additions and 0 deletions
  1. 80 0
      Jenkinsfile

+ 80 - 0
Jenkinsfile

@@ -0,0 +1,80 @@
+pipeline {
+    agent any
+
+    environment {
+       BUILD_USER = ""
+    }
+
+    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 dist.tar.gz dist/'
+            }
+        }
+
+        stage('deploy job') {
+            steps {
+                sshPublisher(publishers: [sshPublisherDesc(configName: 'ECS-CooleShow-47.114.1.200-dev', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'cd /mnt/datadisk/www/cooleshow/colexiu-mall-admin && rm -rf dist/ && tar -zxf *.tar.gz && rm *.tar.gz && systemctl restart nginx', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/mnt/datadisk/www/cooleshow/colexiu-mall-admin', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/*.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
+            }
+        }
+
+        stage('clean job') {
+            steps {
+                sh 'rm dist.tar.gz'
+            }
+        }
+    }
+
+    post {
+        
+        success {
+            dingtalk (
+                robot: "Jenkins",
+                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: "Jenkins",
+                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}",
+                ]
+            )
+        }
+    }
+}