library.develop.jenkinsfile 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 = "develop"
  13. versionSuffix = "-${stageName}${env.build_number}"
  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/develop/"
  26. DOCKER_Buildx = false
  27. DOCKER_USERNAME = " "
  28. DOCKER_PASSWORD = " "
  29. build_crossPlatform = "no"
  30. svn_createReleaseBranch = "no"
  31. svn_changeToNextTempVersion = "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 = "$basePath/build"
  42. env.inputChoice = "no"
  43. env.inputChoice = input message: "deploy ?",
  44. ok: 'Proceed?',
  45. parameters: [choice(choices:["yes","no"], description: 'if not please select no', name: 'choice')]
  46. }
  47. }
  48. }
  49. }
  50. stage('#2 pull code') {
  51. when { expression { env.inputChoice == "yes" } }
  52. steps {
  53. script {
  54. echo "#1.1 pull code from svn to Path: $codePath"
  55. 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; '"
  56. echo "#1.2 change-app-version"
  57. sshCommand remote: remote, command: "sh -c 'set -e; export versionSuffix=$versionSuffix; cd $codePath/Publish/DevOps2/build-bash; sh 20.change-app-version.bash; '"
  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.1 code - create release branch') {
  94. when { expression { env.inputChoice == "yes" && env.svn_createReleaseBranch == "yes" } }
  95. steps {
  96. script {
  97. 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; '"
  98. }
  99. }
  100. }
  101. stage('#6.2 code - next temp version') {
  102. when { expression { env.inputChoice == "yes" && env.svn_changeToNextTempVersion == "yes" } }
  103. steps {
  104. script {
  105. 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; '"
  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 temp files"
  123. sshCommand remote: remote, command: "rm -rf $basePath"
  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. }