包含后厨 团餐 门店分支
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.
 
 
 

143 regels
3.9 KiB

  1. def getHost(){
  2. def remote = [:]
  3. remote.name = 'eip'
  4. remote.host = '10.6.1.50'
  5. remote.user = 'root'
  6. remote.port = 22
  7. remote.password = '120962839'
  8. remote.allowAnyHosts = true
  9. return remote
  10. }
  11. pipeline{
  12. agent any
  13. parameters {
  14. choice(
  15. description: 'EIP环境',
  16. name: 'environment',
  17. choices: ['dev1']
  18. )
  19. choice(
  20. description: '执行操作(发布|回滚)',
  21. name: 'operation',
  22. choices: ['develop', 'rollback']
  23. )
  24. choice(
  25. description: '是否下载包',
  26. name: 'isDownloadPackage',
  27. choices: ['是','否']
  28. )
  29. string(
  30. name: 'tag',
  31. defaultValue: '',
  32. description: '版本tag'
  33. )
  34. }
  35. stages
  36. {
  37. stage('Prepare') {
  38. steps {
  39. script{
  40. echo "1.Prepare Stage"
  41. echo "当前环境${params.environment}"
  42. if(params.operation=='develop')
  43. {
  44. checkout scm
  45. script {
  46. build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
  47. if (env.BRANCH_NAME != 'master') {
  48. build_tag = "${env.BRANCH_NAME}-${build_tag}"
  49. }
  50. }
  51. }
  52. else{
  53. build_tag="${params.tag}"
  54. }
  55. }
  56. }
  57. }
  58. stage('Test') {
  59. steps {
  60. script{
  61. echo "2.Test Stage"
  62. }
  63. }
  64. }
  65. stage('Build') {
  66. steps {
  67. script{
  68. echo "3.Build Docker Image Stage"
  69. if(params.operation=='develop')
  70. {
  71. nodejs("nodejs") {
  72. }
  73. if(params.isDownloadPackage=='是')
  74. {
  75. sh "npm install --unsafe-perm=true --allow-root"
  76. sh "rm -rf ./dist/*"
  77. sh "npm run build"
  78. }
  79. sh "docker build -t 10.2.1.24:10242/bpa/kitchenweb:${build_tag} ."
  80. }
  81. }
  82. }
  83. }
  84. stage('Push') {
  85. steps {
  86. script{
  87. echo "4.Push Docker Image Stage"
  88. withCredentials([usernamePassword(credentialsId: 'harbor', passwordVariable: 'harborPassword', usernameVariable: 'harborUser')]) {
  89. sh "docker login -u ${harborUser} -p ${harborPassword} 10.2.1.24:10242"
  90. if(params.operation=='develop')
  91. {
  92. sh "docker push 10.2.1.24:10242/bpa/kitchenweb:${build_tag}"
  93. }
  94. }
  95. }
  96. }
  97. }
  98. stage('Deploy') {
  99. steps {
  100. script{
  101. echo "5. Deploy Stage"
  102. // server = getHost()
  103. // sshCommand remote: server, command: """
  104. // /root/eip/web/shell/linux-eipweb.install.sh eipweb ${build_tag} 80
  105. // """
  106. sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s_kitchenweb.yaml"
  107. sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_kitchenweb.yaml"
  108. sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_kitchenweb.yaml"
  109. sh "kubectl apply -f k8s_kitchenweb.yaml --record"
  110. }
  111. }
  112. }
  113. }
  114. }