CICD.ki.git_Multibranch.deploy.jenkinsfile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 = " "
  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. // get APPNAME
  38. def APPNAME = readFile("Publish/DevOps2/jenkins-bash/env.appVersion.txt")
  39. env.APPNAME = "${APPNAME}"
  40. env.releasePath = "/root/docker-cache/jenkins/jenkins_home/jenkinsReleaseFile/${stageName}/${env.BRANCH_NAME}/${APPNAME}"
  41. echo "-------- APPNAME: [$APPNAME]"
  42. echo "-------- basePath: [$basePath]"
  43. echo "-------- releasePath: [$releasePath]"
  44. echo "-------- DOCKER_ImagePrefix: [$DOCKER_ImagePrefix]"
  45. echo "-------- codePath: [$codePath]"
  46. env.inputChoice = "no"
  47. env.inputChoice = input message: "deploy ?",
  48. ok: 'Proceed?',
  49. parameters: [choice(choices:["yes","no"], description: 'if not please select no', name: 'choice')]
  50. }
  51. }
  52. }
  53. }
  54. stage('#2 change version') {
  55. when { expression { env.inputChoice == "yes" } }
  56. steps {
  57. script {
  58. echo "#2.1 change-app-version"
  59. 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/DevOps2/jenkins-bash/env.appVersion.txt '"
  60. echo "#2.2 get app version"
  61. def appVersion = readFile("Publish/DevOps2/jenkins-bash/env.appVersion.txt")
  62. env.appVersion = "${appVersion}"
  63. echo "appVersion: [${env.appVersion}]"
  64. }
  65. }
  66. }
  67. stage('#3.1 build - single platflorm') {
  68. when { expression { env.inputChoice == "yes" } }
  69. steps {
  70. script {
  71. 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; '"
  72. }
  73. }
  74. }
  75. stage('#3.2 build - cross platform') {
  76. when { expression { env.inputChoice == "yes" && env.build_crossPlatform == "yes" } }
  77. steps {
  78. script {
  79. 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; '"
  80. }
  81. }
  82. }
  83. stage('#4 publish') {
  84. when { expression { env.inputChoice == "yes" } }
  85. steps {
  86. script {
  87. 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; '"
  88. }
  89. }
  90. }
  91. stage('#5 copy release files') {
  92. when { expression { env.inputChoice == "yes" && env.releasePath != " " } }
  93. steps {
  94. script {
  95. 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; '"
  96. }
  97. }
  98. }
  99. stage('#6 deploy') {
  100. when { expression { env.inputChoice == "yes" && env.build_deploy == "yes" } }
  101. steps {
  102. script {
  103. remote.name = "k8s-ssh"
  104. remote.host = "k8s.lith.cloud"
  105. remote.user = "${k8s_ssh_account_USR}"
  106. remote.password = "${k8s_ssh_account_PSW}"
  107. 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; '"
  108. }
  109. }
  110. }
  111. }
  112. post {
  113. always {
  114. timeout(time:3600,unit:'SECONDS') {
  115. script {
  116. env.inputChoice = "yes"
  117. env.inputChoice = input message: "Clean temp files, \n will wait for 3600 seconds. \n click abort to skip clean.",
  118. ok: 'Proceed',
  119. parameters: [choice(choices:["yes","no"], name: 'choice')]
  120. }
  121. }
  122. script {
  123. if ( inputChoice == "yes" ) {
  124. echo "clean up workspace directory"
  125. cleanWs()
  126. // clean up tmp directory
  127. dir("${workspace}@tmp") {
  128. deleteDir()
  129. }
  130. }
  131. }
  132. }
  133. success {
  134. echo "build success !"
  135. }
  136. failure {
  137. echo "build failure !"
  138. }
  139. aborted {
  140. echo "build aborted !"
  141. }
  142. }
  143. }