CICD.ki.git_Multibranch.deploy.jenkinsfile 6.5 KB

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