五芳斋信息管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

154 rivejä
5.0 KiB

  1. pipeline{
  2. agent any
  3. parameters {
  4. choice(
  5. description: 'wfzapi:开发环境1',
  6. name: 'environment',
  7. choices: ['wfz']
  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 "docker build -f backend/dockerfile -t 10.2.1.24:10242/bpa/wfzapi:${build_tag} ."
  78. }
  79. else if(params.projectqh=='frontend')
  80. {
  81. sh "docker build -f frontend/dockerfile -t 10.2.1.24:10242/bpa/wfzweb:${build_tag} ."
  82. }
  83. }
  84. }
  85. }
  86. }
  87. stage('Push') {
  88. steps {
  89. script{
  90. echo "4.Push Docker Image Stage"
  91. withCredentials([usernamePassword(credentialsId: 'harbor', passwordVariable: 'harborPassword', usernameVariable: 'harborUser')]) {
  92. sh "docker login -u ${harborUser} -p ${harborPassword} 10.2.1.24:10242"
  93. if(params.operation=='develop')
  94. {
  95. if(params.projectqh=='backend')
  96. {
  97. sh "docker push 10.2.1.24:10242/bpa/wfzapi:${build_tag}"
  98. }
  99. else if(params.projectqh=='frontend')
  100. {
  101. sh "docker push 10.2.1.24:10242/bpa/wfzweb:${build_tag}"
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. stage('Deploy') {
  109. steps {
  110. script{
  111. echo "5. Deploy Stage"
  112. // if(params.environment=='test')
  113. // {
  114. // input "确认要部署线上环境吗?"
  115. // }
  116. if(params.projectqh=='backend')
  117. {
  118. sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s_wfzapi.yaml"
  119. sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_wfzapi.yaml"
  120. sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_wfzapi.yaml"
  121. sh "kubectl apply -f k8s_wfzapi.yaml --record"
  122. }
  123. else if(params.projectqh=='frontend')
  124. {
  125. sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s_wfzweb.yaml"
  126. sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_wfzweb.yaml"
  127. sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_wfzweb.yaml"
  128. sh "kubectl apply -f k8s_wfzweb.yaml --record"
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }