基础服务api
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

127 строки
3.6 KiB

  1. pipeline{
  2. agent any
  3. parameters {
  4. choice(
  5. description: 'saasdev1:开发环境1 \n dev2:开发环境2 \n dev3:生产环境',
  6. name: 'environment',
  7. choices: ['saasdev1', 'dev2', '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/saasbase:${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/saasbase:${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_saasbase.yaml"
  98. sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s_saasbase.yaml"
  99. sh "sed -i 's/<NAMESPACES>/${params.environment}/' k8s_saasbase.yaml"
  100. sh "kubectl apply -f k8s_saasbase.yaml --record"
  101. }
  102. }
  103. }
  104. }
  105. }