library.develop.jenkinsfile 6.7 KB

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