CICD.ki.git_Multibranch.deploy.jenkinsfile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. // get APPNAME
  12. // APPNAME = "Sers"
  13. APPNAME = readFile("Publish/DevOps3/environment/env.APPNAME.txt")
  14. envName = readFile("Publish/DevOps3/environment/env.envName.txt")
  15. versionSuffix = "-${envName}${env.build_number}"
  16. //basePath = "/root/docker-cache/jenkins/jenkins_home/workspace/${APPNAME}/${envName}/${env.BRANCH_NAME}/${env.build_number}"
  17. basePath = "${env.WORKSPACE}"
  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/${envName}/"
  23. DOCKER_Buildx = false
  24. DOCKER_USERNAME = " "
  25. DOCKER_PASSWORD = " "
  26. // set to " " if want to skip save releaseFiles to WebDav
  27. WebDav_BaseUrl = "https://pan.lith.cloud:4/remote.php/dav/files/release/releaseFiles/ki_jenkins"
  28. // "username:pwd"
  29. WebDav_User = credentials("WebDav_User")
  30. build_crossPlatform = "no"
  31. dind_ssh_account = credentials("dind_ssh_account")
  32. }
  33. stages {
  34. stage('#1 deploy ?') {
  35. steps {
  36. timeout(time:600,unit:'SECONDS') {
  37. script {
  38. remote.user = "${dind_ssh_account_USR}"
  39. remote.password = "${dind_ssh_account_PSW}"
  40. env.codePath = "/root/docker-cache/jenkins/" + basePath.substring(5, basePath.length())
  41. echo "-------- APPNAME: [$APPNAME]"
  42. echo "-------- basePath: [$basePath]"
  43. echo "-------- DOCKER_ImagePrefix: [$DOCKER_ImagePrefix]"
  44. echo "-------- codePath: [$codePath]"
  45. env.inputChoice = "no"
  46. env.inputChoice = input message: "deploy ?",
  47. ok: 'Proceed?',
  48. parameters: [choice(choices:["yes","no"], description: 'if not please select no', name: 'choice')]
  49. }
  50. }
  51. }
  52. }
  53. stage('#2 change version') {
  54. when { expression { env.inputChoice == "yes" } }
  55. steps {
  56. script {
  57. echo "#2.1 change-app-version"
  58. sshCommand remote: remote, command: "sh -c 'set -e; export versionSuffix=$versionSuffix; cd $codePath/Publish/DevOps3/build-bash; source 22.add-suffix-to-app-version.bash; echo -n \"\$nextAppVersion\" > $codePath/Publish/DevOps3/environment/env.appVersion.txt '"
  59. echo "#2.2 get app version"
  60. env.appVersion = readFile("Publish/DevOps3/environment/env.appVersion.txt")
  61. echo "-------- appVersion: [${env.appVersion}]"
  62. }
  63. }
  64. }
  65. stage('#3.1 build - single platflorm') {
  66. when { expression { env.inputChoice == "yes" } }
  67. steps {
  68. script {
  69. sshCommand remote: remote, command: "sh -c 'set -e; export APPNAME=$APPNAME; export NUGET_PATH=$NUGET_PATH; cd $codePath/Publish/DevOps3/build-bash; sh startup.bash; '"
  70. }
  71. }
  72. }
  73. stage('#3.2 build - cross platform') {
  74. when { expression { env.inputChoice == "yes" && env.build_crossPlatform == "yes" } }
  75. steps {
  76. script {
  77. sshCommand remote: remote, command: "sh -c 'set -e; export APPNAME=$APPNAME; export NUGET_PATH=$NUGET_PATH; cd $codePath/Publish/DevOps3/build-bash; sh 40.Station-publish-multiple.bash; '"
  78. }
  79. }
  80. }
  81. stage('#4 publish') {
  82. when { expression { env.inputChoice == "yes" } }
  83. steps {
  84. script {
  85. 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/DevOps3/release-bash; sh startup.bash; '"
  86. }
  87. }
  88. }
  89. stage('#5 save releaseFiles') {
  90. when { expression { env.inputChoice == "yes" && env.WebDav_BaseUrl != " " } }
  91. steps {
  92. script {
  93. sshCommand remote: remote, command: "sh -c 'set -e; export basePath=\"$codePath\"; export APPNAME=$APPNAME; export appVersion=\"$appVersion\"; export WebDav_BaseUrl=\"$WebDav_BaseUrl\"; export WebDav_User=\"$WebDav_User\"; cd $codePath/Publish/DevOps3/release-bash; sh 78.push-releaseFiles-to-webdav.bash; '"
  94. }
  95. }
  96. }
  97. stage('#6 deploy') {
  98. when { expression { env.inputChoice == "yes" && env.build_deploy == "yes" } }
  99. steps {
  100. script {
  101. remote.name = "k8s-ssh"
  102. remote.host = "k8s.lith.cloud"
  103. remote.user = "${k8s_ssh_account_USR}"
  104. remote.password = "${k8s_ssh_account_PSW}"
  105. 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; '"
  106. }
  107. }
  108. }
  109. }
  110. post {
  111. always {
  112. timeout(time:3600,unit:'SECONDS') {
  113. script {
  114. env.inputChoice = "yes"
  115. env.inputChoice = input message: "Clean temp files, \n will wait for 3600 seconds. \n click abort to skip clean.",
  116. ok: 'Proceed',
  117. parameters: [choice(choices:["yes","no"], name: 'choice')]
  118. }
  119. }
  120. script {
  121. if ( inputChoice == "yes" ) {
  122. echo "clean up workspace directory"
  123. cleanWs()
  124. // clean up tmp directory
  125. dir("${workspace}@tmp") {
  126. deleteDir()
  127. }
  128. }
  129. }
  130. }
  131. success {
  132. echo "build success !"
  133. }
  134. failure {
  135. echo "build failure !"
  136. }
  137. aborted {
  138. echo "build aborted !"
  139. }
  140. }
  141. }