团餐订单
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Jenkinsfile 3.6 KiB

11 månader sedan
11 månader sedan
11 månader sedan
11 månader sedan
11 månader sedan
11 månader sedan
11 månader sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. pipeline{
  2. agent any
  3. parameters {
  4. choice(
  5. description: 'saasdev1:开发环境1 \n saastest1:测试环境2 \n dev3:生产环境',
  6. name: 'environment',
  7. choices: ['saasdev1', 'saastest1', 'dev3']
  8. )
  9. choice(
  10. description: '执行操作(发布|回滚)',
  11. name: 'operation',
  12. choices: ['develop', 'rollback']
  13. )
  14. choice(
  15. description: '分支名',
  16. name: 'branchName',
  17. choices: ['master']
  18. )
  19. string(
  20. name: 'tag',
  21. defaultValue: '',
  22. description: '版本tag'
  23. )
  24. }
  25. stages
  26. {
  27. stage('Prepare') {
  28. steps {
  29. script{
  30. echo "1.Prepare Stage"
  31. echo "当前环境${params.environment}"
  32. if(params.operation=='develop')
  33. {
  34. checkout scm
  35. script {
  36. build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
  37. if (env.BRANCH_NAME != 'master') {
  38. build_tag = "${env.BRANCH_NAME}-${build_tag}"
  39. }
  40. }
  41. }
  42. else{
  43. script {
  44. if(params.branchName!= 'master')
  45. {
  46. build_tag = "${params.branchName}-${params.tag}"
  47. }
  48. else
  49. {
  50. build_tag="${params.tag}"
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. stage('Test') {
  58. steps {
  59. script{
  60. echo "2.Test Stage"
  61. }
  62. }
  63. }
  64. stage('Build') {
  65. steps {
  66. script{
  67. echo "3.Build Docker Image Stage"
  68. if(params.operation=='develop')
  69. {
  70. sh "docker build -t 10.2.1.24:10242/bpa/groupmealorder:${build_tag} ."
  71. }
  72. }
  73. }
  74. }
  75. stage('Push') {
  76. steps {
  77. script{
  78. echo "4.Push Docker Image Stage"
  79. withCredentials([usernamePassword(credentialsId: 'harbor', passwordVariable: 'harborPassword', usernameVariable: 'harborUser')]) {
  80. sh "docker login -u ${harborUser} -p ${harborPassword} 10.2.1.24:10242"
  81. if(params.operation=='develop')
  82. {
  83. sh "docker push 10.2.1.24:10242/bpa/groupmealorder:${build_tag}"
  84. }
  85. }
  86. }
  87. }
  88. }
  89. stage('Deploy') {
  90. steps {
  91. script{
  92. echo "5. Deploy Stage"
  93. // if(params.environment=='test')
  94. // {
  95. // input "确认要部署线上环境吗?"
  96. // }
  97. sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s_groupmealorder.yaml"
  98. sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_groupmealorder.yaml"
  99. sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_groupmealorder.yaml"
  100. sh "kubectl apply -f k8s_groupmealorder.yaml --record"
  101. }
  102. }
  103. }
  104. }
  105. }