Vladimir Khlyunev | 8bad6a6 | 2022-10-06 00:29:59 +0400 | [diff] [blame] | 1 | |
| 2 | @NonCPS |
| 3 | def getPluginList(){ |
| 4 | def pluginList = new ArrayList(Jenkins.instance.pluginManager.plugins) |
| 5 | def pluginListText = "" |
| 6 | pluginList.each{ |
| 7 | plugin -> |
| 8 | pluginListText += """${plugin.getShortName()}.hpi\n""" |
| 9 | } |
| 10 | return pluginListText |
| 11 | } |
| 12 | |
| 13 | node('sre-team-infra') { |
| 14 | timestamps() { |
| 15 | ansiColor('xterm') { |
| 16 | stage('Checkout') { |
| 17 | checkout scm |
| 18 | } |
| 19 | storageDir = "${WORKSPACE}/storage" |
| 20 | stage('Prepare storage dir'){ |
| 21 | sh "rm -rf ${storageDir} && mkdir -p ${storageDir}" |
| 22 | } |
| 23 | stage('Generate plugin urls'){ |
| 24 | pluginList = getPluginList() |
| 25 | writeFile file: "${storageDir}/plugin_list.txt", text: "${pluginList}" |
| 26 | } |
| 27 | stage('Generate backup archive'){ |
| 28 | sh 'bash jobs/backups/sre-jenkins-backup.sh' |
| 29 | } |
| 30 | stage('Upload backups to remote hosts'){ |
| 31 | remoteHosts = ['172.19.119.254', 'srv02-srt.srt.mirantis.net', 'srv08-srt.infra.mirantis.net'] |
| 32 | errCount = 0 |
| 33 | sshagent(credentials: ['maintenance-team-ssh']) { |
| 34 | remoteHosts.each{ host -> |
| 35 | try { |
| 36 | sh "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null jenkins@${host} mkdir -p /home/jenkins/sre-jenkins-backups" |
| 37 | sh "rsync -avz ${storageDir}/*.tar.gz -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' jenkins@${host}:/home/jenkins/sre-jenkins-backups/" |
| 38 | } catch (Exception e) { |
| 39 | errCount+=1 |
| 40 | } |
| 41 | if (remoteHosts.size() == errCount) { |
| 42 | throw Exception('All remote hosts are not reachable!') |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |