library.preview.jenkinsfile 6.1 KB

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