library.production.jenkinsfile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 = "production"
  13. versionSuffix = " "
  14. basePath = "/root/docker-cache/jenkins/jenkins_home/workspace/${APPNAME}/${stageName}/${env.build_number}"
  15. // set to " " if want to skip copy
  16. releasePath = "/root/docker-cache/jenkins/jenkins_home/jenkinsReleaseFile/${stageName}/${APPNAME}"
  17. SVN_PATH = "svn://svn.ki.lith.cloud/Sers"
  18. //svn_USR = " "
  19. //svn_PSW = " "
  20. svn = credentials("svn_account")
  21. NUGET_PATH = "/root/docker-cache/jenkins/jenkins_home/workspace/.nuget"
  22. NUGET_SERVER = "http://nuget.lith.cloud:8"
  23. //NUGET_KEY = " "
  24. NUGET_KEY = credentials("nuget_key")
  25. DOCKER_ImagePrefix = "docker.lith.cloud:8/"
  26. DOCKER_USERNAME = " "
  27. DOCKER_PASSWORD = " "
  28. build_crossPlatform = "yes"
  29. svn_createReleaseBranch = "yes"
  30. svn_changeToNextTempVersion = "yes"
  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 = "$basePath/build"
  41. env.inputChoice = "no"
  42. env.inputChoice = input message: "deploy ?",
  43. ok: 'Proceed?',
  44. parameters: [choice(choices:["yes","no"], description: 'if not please select no', name: 'choice')]
  45. }
  46. }
  47. }
  48. }
  49. stage('#2 pull code') {
  50. when { expression { env.inputChoice == "yes" } }
  51. steps {
  52. script {
  53. echo "#1.1 pull code from svn to Path: $codePath"
  54. sshCommand remote: remote, command: "sh -c 'set -e; mkdir -p $codePath;chmod 777 $codePath; docker run -i --rm -v $codePath:/root/svn serset/svn-client svn checkout \"$SVN_PATH/branches/develop\" /root/svn --username \"$svn_USR\" --password \"$svn_PSW\" --no-auth-cache > /dev/null; '"
  55. echo "#1.2 change-app-version"
  56. sshCommand remote: remote, command: "sh -c 'set -e; export versionSuffix=$versionSuffix; cd $codePath/Publish/DevOps2/build-bash; sh 20.change-app-version.bash; '"
  57. }
  58. }
  59. }
  60. stage('#3.1 build - single platflorm') {
  61. when { expression { env.inputChoice == "yes" } }
  62. steps {
  63. script {
  64. 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; '"
  65. }
  66. }
  67. }
  68. stage('#3.2 build - cross platform') {
  69. when { expression { env.inputChoice == "yes" && env.build_crossPlatform == "yes" } }
  70. steps {
  71. script {
  72. 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; '"
  73. }
  74. }
  75. }
  76. stage('#4 publish') {
  77. when { expression { env.inputChoice == "yes" } }
  78. steps {
  79. script {
  80. 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_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; '"
  81. }
  82. }
  83. }
  84. stage('#5 copy release files') {
  85. when { expression { env.inputChoice == "yes" && env.releasePath != " " } }
  86. steps {
  87. script {
  88. sshCommand remote: remote, command: "sh -c 'set -e; export versionSuffix=$versionSuffix; cd $codePath/Publish/DevOps2/build-bash; source 19.get-app-version.bash; echo \"copy release files : $codePath/Publish/release/release-zip/. $releasePath/\$appVersion;\"; mkdir -p $releasePath; \\cp -rf $codePath/Publish/release/release-zip/. $releasePath/\$appVersion; '"
  89. }
  90. }
  91. }
  92. stage('#6.1 code - create release branch') {
  93. when { expression { env.inputChoice == "yes" && env.svn_createReleaseBranch == "yes" } }
  94. steps {
  95. script {
  96. sshCommand remote: remote, command: "sh -c 'set -e; export codePath=\"$basePath/code-createReleaseBranch\";export SVN_PATH=$SVN_PATH;export SVN_USERNAME=\"$svn_USR\";export SVN_PASSWORD=\"$svn_PSW\"; export versionSuffix=$versionSuffix; cd $codePath/Publish/DevOps2/jenkins-bash; sh 06.svn-createReleaseBranch.bash; '"
  97. }
  98. }
  99. }
  100. stage('#6.2 code - next temp version') {
  101. when { expression { env.inputChoice == "yes" && env.svn_changeToNextTempVersion == "yes" } }
  102. steps {
  103. script {
  104. sshCommand remote: remote, command: "sh -c 'set -e; export codePath=\"$basePath/code-nextTempVersion\";export SVN_PATH=$SVN_PATH;export SVN_USERNAME=\"$svn_USR\";export SVN_PASSWORD=\"$svn_PSW\"; cd $codePath/Publish/DevOps2/jenkins-bash; sh 07.svn-changeToNextTempVersion.bash; '"
  105. }
  106. }
  107. }
  108. }
  109. post {
  110. always {
  111. timeout(time:3600,unit:'SECONDS') {
  112. script {
  113. env.inputChoice = "yes"
  114. env.inputChoice = input message: "Clean temp files, \n will wait for 3600 seconds. \n click abort to skip clean.",
  115. ok: 'Proceed',
  116. parameters: [choice(choices:["yes","no"], name: 'choice')]
  117. }
  118. }
  119. script {
  120. if ( inputChoice == "yes" ) {
  121. echo "clean temp files"
  122. sshCommand remote: remote, command: "rm -rf $basePath"
  123. }
  124. }
  125. }
  126. success {
  127. echo "build success !"
  128. }
  129. failure {
  130. echo "build failure !"
  131. }
  132. aborted {
  133. echo "build aborted !"
  134. }
  135. }
  136. }