集成,总结MES功能
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.
 
 
 
 

157 lines
4.9 KiB

  1. def getHost(){
  2. def remote = [:]
  3. remote.name = 'eip'
  4. remote.host = '10.2.1.254'
  5. remote.user = 'root'
  6. remote.port = 22
  7. remote.password = 'bpaadmin'
  8. remote.allowAnyHosts = true
  9. return remote
  10. }
  11. pipeline{
  12. agent any
  13. parameters {
  14. choice(
  15. description: '前端or后端',
  16. name: 'projectqh',
  17. choices: ['backend','frontend']
  18. )
  19. choice(
  20. description: '执行操作(发布|回滚)',
  21. name: 'operation',
  22. choices: ['develop', 'rollback']
  23. )
  24. choice(
  25. description: '分支名',
  26. name: 'branchName',
  27. choices: ['master']
  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/finalapi:${build_tag} ."
  79. }
  80. else if(params.projectqh=='frontend')
  81. {
  82. sh "docker build -f frontend/dockerfile -t 10.2.1.24:10242/bpa/finalweb:${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/finalapi:${build_tag}"
  99. }
  100. else if(params.projectqh=='frontend')
  101. {
  102. sh "docker push 10.2.1.24:10242/bpa/finalweb:${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. server = getHost()
  120. sshCommand remote: server, command: """
  121. /home/finalmes/api/install.sh ${build_tag}
  122. """
  123. }
  124. else if(params.projectqh=='frontend')
  125. {
  126. server = getHost()
  127. sshCommand remote: server, command: """
  128. /home/finalmes/web/install.sh ${build_tag}
  129. """
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }