CICD.ki.git_Multibranch.deploy.jenkinsfile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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/environment/env.APPNAME.txt")
  14. envName = readFile("Publish/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. if ( fileExists("Publish/environment/jenkins_NoNeedApprovalForBuild.txt") ) {
  47. echo "-------- do not need approval for build"
  48. env.ApprovalForBuild = "yes"
  49. } else {
  50. echo "-------- waiting approval for build"
  51. env.ApprovalForBuild = "no"
  52. env.ApprovalForBuild = input message: "deploy ?",
  53. ok: 'Proceed?',
  54. parameters: [choice(choices:["yes","no"], description: 'if not please select no', name: 'choice')]
  55. }
  56. }
  57. }
  58. }
  59. }
  60. stage('#2 change version') {
  61. when { expression { env.ApprovalForBuild == "yes" } }
  62. steps {
  63. script {
  64. echo "#2.1 change-app-version"
  65. 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/environment/env.appVersion.txt '"
  66. echo "#2.2 get app version"
  67. env.appVersion = readFile("Publish/environment/env.appVersion.txt")
  68. echo "-------- appVersion: [${env.appVersion}]"
  69. }
  70. }
  71. }
  72. stage('#3.0 build - run test') {
  73. when { expression { env.ApprovalForBuild == "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/DevOps3/build-bash; sh 10.Test.bash; '"
  77. }
  78. }
  79. }
  80. stage('#3.1 build - single platflorm') {
  81. when { expression { env.ApprovalForBuild == "yes" } }
  82. steps {
  83. script {
  84. 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; '"
  85. }
  86. }
  87. }
  88. stage('#3.2 build - cross platform') {
  89. when { expression { env.ApprovalForBuild == "yes" && env.build_crossPlatform == "yes" } }
  90. steps {
  91. script {
  92. 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; '"
  93. }
  94. }
  95. }
  96. stage('#4 publish') {
  97. when { expression { env.ApprovalForBuild == "yes" } }
  98. steps {
  99. script {
  100. 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; '"
  101. }
  102. }
  103. }
  104. stage('#5 save releaseFiles') {
  105. when { expression { env.ApprovalForBuild == "yes" && env.WebDav_BaseUrl != " " } }
  106. steps {
  107. script {
  108. 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; '"
  109. }
  110. }
  111. }
  112. }
  113. post {
  114. always {
  115. timeout(time:600,unit:'SECONDS') {
  116. script {
  117. env.CleanFiles = "yes"
  118. env.CleanFiles = input message: "Clean temp files, \n will wait for 3600 seconds. \n click abort to skip clean.",
  119. ok: 'Proceed',
  120. parameters: [choice(choices:["yes","no"], name: 'choice')]
  121. }
  122. }
  123. script {
  124. if ( CleanFiles == "yes" ) {
  125. echo "clean up workspace directory"
  126. cleanWs()
  127. // clean up tmp directory
  128. dir("${workspace}@tmp") {
  129. deleteDir()
  130. }
  131. }
  132. }
  133. }
  134. success {
  135. echo "build success !"
  136. }
  137. failure {
  138. echo "build failure !"
  139. }
  140. aborted {
  141. echo "build aborted !"
  142. }
  143. }
  144. }