吉香居中控系统
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

155 řádky
5.1 KiB

  1. pipeline{
  2. agent any
  3. parameters {
  4. choice(
  5. description: 'jxjwebi:开发环境1',
  6. name: 'environment',
  7. choices: ['jxj']
  8. )
  9. choice(
  10. description: '前端or后端',
  11. name: 'projectqh',
  12. choices: ['backend','frontend']
  13. )
  14. choice(
  15. description: '执行操作(发布|回滚)',
  16. name: 'operation',
  17. choices: ['develop', 'rollback']
  18. )
  19. choice(
  20. description: '分支名',
  21. name: 'branchName',
  22. choices: ['master']
  23. )
  24. string(
  25. name: 'tag',
  26. defaultValue: '',
  27. description: '版本tag'
  28. )
  29. }
  30. stages
  31. {
  32. stage('Prepare') {
  33. steps {
  34. script{
  35. echo "1.Prepare Stage"
  36. echo "当前环境${params.environment}"
  37. if(params.operation=='develop')
  38. {
  39. checkout scm
  40. script {
  41. build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
  42. if (env.BRANCH_NAME != 'master') {
  43. build_tag = "${env.BRANCH_NAME}-${build_tag}"
  44. }
  45. }
  46. }
  47. else{
  48. script {
  49. if(params.branchName!= 'master')
  50. {
  51. build_tag = "${params.branchName}-${params.tag}"
  52. }
  53. else
  54. {
  55. build_tag="${params.tag}"
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. stage('Test') {
  63. steps {
  64. script{
  65. echo "2.Test Stage"
  66. }
  67. }
  68. }
  69. stage('Build') {
  70. steps {
  71. script{
  72. echo "3.Build Docker Image Stage"
  73. if(params.operation=='develop')
  74. {
  75. if(params.projectqh=='backend')
  76. {
  77. sh "cp -r backend/* ./"
  78. sh "docker build -f backend/dockerfile -t 10.2.1.24:10242/bpa/jxjapi:${build_tag} ."
  79. }
  80. else if(params.projectqh=='frontend')
  81. {
  82. sh "docker build -f frontend/dockerfile -t 10.2.1.24:10242/bpa/jxjweb:${build_tag} ."
  83. }
  84. }
  85. }
  86. }
  87. }
  88. stage('Push') {
  89. steps {
  90. script{
  91. echo "4.Push Docker Image Stage"
  92. withCredentials([usernamePassword(credentialsId: 'harbor', passwordVariable: 'harborPassword', usernameVariable: 'harborUser')]) {
  93. sh "docker login -u ${harborUser} -p ${harborPassword} 10.2.1.24:10242"
  94. if(params.operation=='develop')
  95. {
  96. if(params.projectqh=='backend')
  97. {
  98. sh "docker push 10.2.1.24:10242/bpa/jxjapi:${build_tag}"
  99. }
  100. else if(params.projectqh=='frontend')
  101. {
  102. sh "docker push 10.2.1.24:10242/bpa/jxjweb:${build_tag}"
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. stage('Deploy') {
  110. steps {
  111. script{
  112. echo "5. Deploy Stage"
  113. // if(params.environment=='test')
  114. // {
  115. // input "确认要部署线上环境吗?"
  116. // }
  117. if(params.projectqh=='backend')
  118. {
  119. sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s_jxjapi.yaml"
  120. sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_jxjapi.yaml"
  121. sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_jxjapi.yaml"
  122. sh "kubectl apply -f k8s_jxjapi.yaml --record"
  123. }
  124. else if(params.projectqh=='frontend')
  125. {
  126. sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s_jxjweb.yaml"
  127. sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_jxjweb.yaml"
  128. sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_jxjweb.yaml"
  129. sh "kubectl apply -f k8s_jxjweb.yaml --record"
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }