CICD.ki.git_Multibranch.deploy.jenkinsfile 6.9 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_PATH = credentials("NUGET_PATH")
  20. NUGET_SERVER = credentials("NUGET_SERVER")
  21. NUGET_KEY = credentials("NUGET_KEY")
  22. DOCKER_SERVER = credentials("DOCKER_SERVER")
  23. DOCKER_ImagePrefix = "${DOCKER_SERVER}/${envName}/"
  24. DOCKER_Buildx = false
  25. DOCKER_USERNAME = " "
  26. DOCKER_PASSWORD = " "
  27. // set to " " if want to skip save releaseFiles to WebDav
  28. WebDav_BaseUrl = credentials("WebDav_BaseUrl")
  29. // WebDav_User = "username:pwd"
  30. WebDav_User = credentials("WebDav_User")
  31. build_crossPlatform = "no"
  32. dind_ssh_account = credentials("dind_ssh_account")
  33. }
  34. stages {
  35. stage('#1 deploy ?') {
  36. steps {
  37. timeout(time:600,unit:'SECONDS') {
  38. script {
  39. remote.user = "${dind_ssh_account_USR}"
  40. remote.password = "${dind_ssh_account_PSW}"
  41. env.codePath = "/root/docker-cache/jenkins/" + basePath.substring(5, basePath.length())
  42. echo "-------- APPNAME: [$APPNAME]"
  43. echo "-------- basePath: [$basePath]"
  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/DevOps3/build-bash; source 22.add-suffix-to-app-version.bash; echo -n \"\$nextAppVersion\" > $codePath/Publish/DevOps3/environment/env.appVersion.txt '"
  60. echo "#2.2 get app version"
  61. env.appVersion = readFile("Publish/DevOps3/environment/env.appVersion.txt")
  62. echo "-------- appVersion: [${env.appVersion}]"
  63. }
  64. }
  65. }
  66. stage('#3.1 build - single platflorm') {
  67. when { expression { env.inputChoice == "yes" } }
  68. steps {
  69. script {
  70. 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; '"
  71. }
  72. }
  73. }
  74. stage('#3.2 build - cross platform') {
  75. when { expression { env.inputChoice == "yes" && env.build_crossPlatform == "yes" } }
  76. steps {
  77. script {
  78. 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; '"
  79. }
  80. }
  81. }
  82. stage('#4 publish') {
  83. when { expression { env.inputChoice == "yes" } }
  84. steps {
  85. script {
  86. 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; '"
  87. }
  88. }
  89. }
  90. stage('#5 save releaseFiles') {
  91. when { expression { env.inputChoice == "yes" && env.WebDav_BaseUrl != " " } }
  92. steps {
  93. script {
  94. 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; '"
  95. }
  96. }
  97. }
  98. stage('#6 deploy') {
  99. when { expression { env.inputChoice == "yes" && env.build_deploy == "yes" } }
  100. steps {
  101. script {
  102. remote.name = "k8s-ssh"
  103. remote.host = "k8s.lith.cloud"
  104. remote.user = "${k8s_ssh_account_USR}"
  105. remote.password = "${k8s_ssh_account_PSW}"
  106. 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; '"
  107. }
  108. }
  109. }
  110. }
  111. post {
  112. always {
  113. timeout(time:3600,unit:'SECONDS') {
  114. script {
  115. env.inputChoice = "yes"
  116. env.inputChoice = input message: "Clean temp files, \n will wait for 3600 seconds. \n click abort to skip clean.",
  117. ok: 'Proceed',
  118. parameters: [choice(choices:["yes","no"], name: 'choice')]
  119. }
  120. }
  121. script {
  122. if ( inputChoice == "yes" ) {
  123. echo "clean up workspace directory"
  124. cleanWs()
  125. // clean up tmp directory
  126. dir("${workspace}@tmp") {
  127. deleteDir()
  128. }
  129. }
  130. }
  131. }
  132. success {
  133. echo "build success !"
  134. }
  135. failure {
  136. echo "build failure !"
  137. }
  138. aborted {
  139. echo "build aborted !"
  140. }
  141. }
  142. }