CICD.ki.git_Multibranch.deploy.jenkinsfile 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. def remote = [:]
  2. remote.name = "dind-ssh"
  3. remote.host = "dind"
  4. remote.port = 22
  5. remote.user = " "
  6. remote.password = " "
  7. remote.allowAnyHosts = true
  8. pipeline {
  9. agent any
  10. environment {
  11. //APPNAME = "Sers"
  12. stageName = "ki"
  13. versionSuffix = "-${stageName}${env.build_number}"
  14. //basePath = "/root/docker-cache/jenkins/jenkins_home/workspace/${APPNAME}/${stageName}/${env.BRANCH_NAME}/${env.build_number}"
  15. basePath="${env.WORKSPACE}"
  16. // set to " " if want to skip copy
  17. releasePath = "/root/docker-cache/jenkins/jenkins_home/jenkinsReleaseFile/${stageName}/${env.BRANCH_NAME}/${APPNAME}"
  18. NUGET_PATH = "/root/docker-cache/jenkins/jenkins_home/workspace/.nuget"
  19. NUGET_SERVER = "http://nuget.lith.cloud:8"
  20. //NUGET_KEY = " "
  21. NUGET_KEY = credentials("nuget_key")
  22. DOCKER_ImagePrefix = "docker.lith.cloud:8/${stageName}/"
  23. DOCKER_Buildx = false
  24. DOCKER_USERNAME = " "
  25. DOCKER_PASSWORD = " "
  26. build_crossPlatform = "no"
  27. dind_ssh_account = credentials("dind_ssh_account")
  28. }
  29. stages {
  30. stage('#1 deploy ?') {
  31. steps {
  32. timeout(time:600,unit:'SECONDS') {
  33. script {
  34. remote.user = "${dind_ssh_account_USR}"
  35. remote.password = "${dind_ssh_account_PSW}"
  36. env.codePath = "/root/docker-cache/jenkins/" + basePath.substring(5, basePath.length())
  37. echo "-------- APPNAME: [$APPNAME]"
  38. echo "-------- basePath: [$basePath]"
  39. echo "-------- releasePath: [$releasePath]"
  40. echo "-------- DOCKER_ImagePrefix: [$DOCKER_ImagePrefix]"
  41. echo "-------- codePath: [$codePath]"
  42. env.inputChoice = "no"
  43. env.inputChoice = input message: "deploy ?",
  44. ok: 'Proceed?',
  45. parameters: [choice(choices:["yes","no"], description: 'if not please select no', name: 'choice')]
  46. }
  47. }
  48. }
  49. }
  50. stage('#2 change version') {
  51. when { expression { env.inputChoice == "yes" } }
  52. steps {
  53. script {
  54. echo "#2.1 change-app-version"
  55. sshCommand remote: remote, command: "sh -c 'set -e; export versionSuffix=$versionSuffix; cd $codePath/Publish/DevOps2/build-bash; source 22.add-suffix-to-app-version.bash; echo \$nextAppVersion > $codePath/Publish/appVersion.txt '"
  56. echo "#2.2 get app version"
  57. def data = readFile("Publish/appVersion.txt")
  58. def lines = data.readLines()
  59. env.appVersion = lines[0]
  60. echo "appVersion: [${env.appVersion}]"
  61. }
  62. }
  63. }
  64. stage('#3.1 build - single platflorm') {
  65. when { expression { env.inputChoice == "yes" } }
  66. steps {
  67. script {
  68. sshCommand remote: remote, command: "sh -c 'set -e; export APPNAME=$APPNAME; export NUGET_PATH=$NUGET_PATH; cd $codePath/Publish/DevOps2/build-bash; sh startup.bash; '"
  69. }
  70. }
  71. }
  72. stage('#3.2 build - cross platform') {
  73. when { expression { env.inputChoice == "yes" && env.build_crossPlatform == "yes" } }
  74. steps {
  75. script {
  76. sshCommand remote: remote, command: "sh -c 'set -e; export APPNAME=$APPNAME; export NUGET_PATH=$NUGET_PATH; cd $codePath/Publish/DevOps2/build-bash; sh 40.Station-publish-multiple.bash; '"
  77. }
  78. }
  79. }
  80. stage('#4 publish') {
  81. when { expression { env.inputChoice == "yes" } }
  82. steps {
  83. script {
  84. sshCommand remote: remote, command: "sh -c 'set -e; export APPNAME=$APPNAME;export NUGET_PATH=$NUGET_PATH; export NUGET_SERVER=$NUGET_SERVER;export NUGET_KEY=$NUGET_KEY; export DOCKER_Buildx=${env.DOCKER_Buildx};export DOCKER_ImagePrefix=${env.DOCKER_ImagePrefix};export DOCKER_USERNAME=${env.DOCKER_USERNAME};export DOCKER_PASSWORD=${env.DOCKER_PASSWORD};export DOCKER_BuildxExtArgs=\"--output=type=registry,registry.insecure=true\"; cd $codePath/Publish/DevOps2/release-bash; sh startup.bash; '"
  85. }
  86. }
  87. }
  88. stage('#5 copy release files') {
  89. when { expression { env.inputChoice == "yes" && env.releasePath != " " } }
  90. steps {
  91. script {
  92. sshCommand remote: remote, command: "sh -c 'set -e; export versionSuffix=$versionSuffix; cd $codePath/Publish/DevOps2/build-bash; source 19.get-app-version.bash; export appVersion=\$nextAppVersion; echo \"copy release files : $codePath/Publish/release/release-zip/. $releasePath/\$appVersion;\"; mkdir -p $releasePath; \\cp -rf $codePath/Publish/release/release-zip/. $releasePath/\$appVersion; '"
  93. }
  94. }
  95. }
  96. stage('#6 deploy') {
  97. when { expression { env.inputChoice == "yes" && env.build_deploy == "yes" } }
  98. steps {
  99. script {
  100. remote.name = "k8s-ssh"
  101. remote.host = "k8s.lith.cloud"
  102. remote.user = "${k8s_ssh_account_USR}"
  103. remote.password = "${k8s_ssh_account_PSW}"
  104. sshCommand remote: remote, command: "sh -c 'set -e; cd /home/DataStore/Local/Data/2000/200.flowtea-prod/helm; helm upgrade flowtea --set appNum=200 --set debug=true --set resources.limits=false --set image.host=\"\" --set image.tag=\"${env.appVersion}\" --set storageClass.ssd=nfs-prod-ssd --set storageClass.hdd=nfs-prod-hdd ./flowtea -n flowtea; '"
  105. }
  106. }
  107. }
  108. }
  109. post {
  110. always {
  111. timeout(time:3600,unit:'SECONDS') {
  112. script {
  113. env.inputChoice = "yes"
  114. env.inputChoice = input message: "Clean temp files, \n will wait for 3600 seconds. \n click abort to skip clean.",
  115. ok: 'Proceed',
  116. parameters: [choice(choices:["yes","no"], name: 'choice')]
  117. }
  118. }
  119. script {
  120. if ( inputChoice == "yes" ) {
  121. echo "clean up workspace directory"
  122. cleanWs()
  123. // clean up tmp directory
  124. dir("${workspace}@tmp") {
  125. deleteDir()
  126. }
  127. }
  128. }
  129. }
  130. success {
  131. echo "build success !"
  132. }
  133. failure {
  134. echo "build failure !"
  135. }
  136. aborted {
  137. echo "build aborted !"
  138. }
  139. }
  140. }