Jenkinsfile 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!groovy
  2. @Library('jenkinslib') _
  3. def build = new org.devops.build()
  4. def color = new org.devops.color()
  5. def systemtime = new org.devops.systemtime()
  6. def String cpu = "${env.cpu}"
  7. def String imagePrefix = "${env.imagePrefix}"
  8. def String buildImage = "${env.buildImage}"
  9. pipeline {
  10. agent {
  11. node {
  12. label 'master'
  13. }
  14. }
  15. options {
  16. disableConcurrentBuilds()
  17. buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '20')
  18. }
  19. //设定2个参数,根据项目类型不同,修改对应的description name value visibleItemCount defaultValue 即可
  20. parameters {
  21. choice choices: ['false', 'true'], description: '是否需要打镜像包,默认为否', name: 'buildImage'
  22. extendedChoice description: '只有在需要打镜像包的情况下,才需要选择CPU架构。可单选/多选/全选', multiSelectDelimiter: ',', name: 'cpu',
  23. quoteValue: true,
  24. saveJSONParameterToFile: false,
  25. type: 'PT_CHECKBOX',
  26. value: 'x86,arm64',
  27. visibleItemCount: 5
  28. // 需修改对应的镜像名称
  29. string defaultValue: 'bus.ga/jzywb/dcuc/', description: '只有在需要打镜像包的情况下,才需要填写要打镜像通用前缀名称,注意最后面要加 / ', name: 'imagePrefix', trim: false
  30. }
  31. stages {
  32. stage('MAVEN-BUILD') {
  33. steps {
  34. script {
  35. color.PrintMes('执行mvn打包', 'green')
  36. //使用mvn方法打包,并传入打包参数.根据实际情况修改打包策略
  37. build.Build('mvn', 'mvn clean deploy -DskipTests=true', 'master')
  38. }
  39. }
  40. post {
  41. success {
  42. script {
  43. version = build.GetMvnParentVersion()
  44. systime = systemtime.GetSysTime('yyMMdd')
  45. //将打出来的tar包,按照命名规范命名。根据实际情况,修改对应的系统简称和区域标识(DCUC-AUTH-SERVICE-TJDSJ)
  46. sh """cd dcuc-auth-service/target
  47. cp dcuc-auth-service-*.tar.gz DCUC-AUTH-SERVICE-TJDSJ-${version}-${env.GIT_COMMIT.take(8)}-BETA-${systime}.tar.gz
  48. """
  49. //将复制的按照命名规范的tar包提取到Jenkins的面板,方便下载。根据实际情况,修改对应的系统简称和区域标识(DCUC-AUTH-SERVICE-TJDSJ)
  50. archiveArtifacts artifacts: 'dcuc-auth-service/target/DCUC-AUTH-SERVICE-TJDSJ-*.tar.gz'
  51. }
  52. }
  53. }
  54. }
  55. stage('DOCKER-BUILD') {
  56. when {
  57. expression {
  58. return (buildImage == 'true')
  59. }
  60. }
  61. steps {
  62. script {
  63. //将cpu架构和模块名称传入方法打镜像包.若在上面定义的参数名称没变,可不修改
  64. build.BuildImage("${cpu}")
  65. }
  66. }
  67. }
  68. }
  69. //构建后的操作,用来显示结果.所有项目都适用,可不改
  70. post {
  71. success {
  72. wrap([$class: 'BuildUser']) {
  73. script {
  74. currentBuild.description = "Start By ${env.BUILD_USER} And Build Success"
  75. }
  76. }
  77. }
  78. failure {
  79. wrap([$class: 'BuildUser']) {
  80. script {
  81. currentBuild.description = "Start By ${env.BUILD_USER} And Build Failure"
  82. }
  83. }
  84. }
  85. unstable {
  86. wrap([$class: 'BuildUser']) {
  87. script {
  88. currentBuild.description = "Start By ${env.BUILD_USER} And Build Unstable"
  89. }
  90. }
  91. }
  92. }
  93. }