Jenkinsfile 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!groovy
  2. @Library('jenkinslib') _
  3. def color = new org.devops.color()
  4. def build = new org.devops.build()
  5. def systemtime = new org.devops.systemtime()
  6. pipeline {
  7. agent {
  8. node {
  9. label 'master'
  10. }
  11. }
  12. options {
  13. buildDiscarder(logRotator(numToKeepStr: '10'))
  14. disableConcurrentBuilds()
  15. }
  16. stages {
  17. stage('NPM BUILD') {
  18. steps {
  19. script {
  20. sh """rm -fr dist"""
  21. color.PrintMes('执行npm打包','green')
  22. //标准的打包命令.如有需要添加安装ui组件,请直接在对应位置(一般在node-sass 那加 && npm install 包名)
  23. build.Build('npm','npm install && npm run build','master')
  24. }
  25. }
  26. }
  27. }
  28. post {
  29. success {
  30. wrap([$class: 'BuildUser']) {
  31. script {
  32. systime = systemtime.GetSysTime('yyMMdd')
  33. //读取根目录下的package.json,并解析
  34. result = build.GetNpmVersion('package.json')
  35. name = result[0]
  36. version = result[1]
  37. //删除上一次打包时候的tar包
  38. sh """ rm -fr target
  39. mkdir target
  40. tar --exclude-vcs -czvf target/${name}-${version}-${env.GIT_COMMIT.take(8)}-BETA-${systime}.tar.gz dist/ """
  41. archiveArtifacts 'target/*.tar.gz'
  42. currentBuild.description = "Start By ${env.BUILD_USER} And Build Success"
  43. }
  44. }
  45. }
  46. failure {
  47. wrap([$class: 'BuildUser']) {
  48. script {
  49. currentBuild.description = "Start By ${env.BUILD_USER} And Build Failure"
  50. }
  51. }
  52. }
  53. }
  54. }