From 01b8623c482a3c89bd738c933834c669a2c82d21 Mon Sep 17 00:00:00 2001
From: Christian Poessinger <christian@poessinger.com>
Date: Sat, 14 Sep 2019 16:48:53 +0200
Subject: Jenkins: deploy ISO to dev.packages.vyos.net

---
 Jenkinsfile | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

(limited to 'Jenkinsfile')

diff --git a/Jenkinsfile b/Jenkinsfile
index a5bbd89c..71b538c2 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,6 +1,5 @@
 #!/usr/bin/env groovy
-
-// Copyright (C) 2018 VyOS maintainers and contributors
+// Copyright (C) 2019 VyOS maintainers and contributors
 //
 // This program is free software; you can redistribute it and/or modify
 // in order to easy exprort images built to "external" world
@@ -18,7 +17,8 @@
 @NonCPS
 
 def getGitBranchName() {
-    return scm.branches[0].name
+    def branch = scm.branches[0].name
+    return branch.split('/')[-1]
 }
 
 def getGitRepoURL() {
@@ -98,7 +98,32 @@ pipeline {
     }
     post {
         success {
-            archiveArtifacts artifacts: 'build/live-image-*.iso', fingerprint: true
+            // publish build result, using SSH-dev.packages.vyos.net Jenkins Credentials
+            sshagent(['SSH-dev.packages.vyos.net']) {
+                script {
+                    // build up some fancy groovy variables so we do not need to write/copy
+                    // every option over and over again!
+                    def ARCH = sh(returnStdout: true, script: "dpkg --print-architecture").trim()
+                    def SSH_DIR = '/home/sentrium/web/downloads.vyos.io/public_html/rolling/' + getGitBranchName() + '/' + ARCH
+                    def SSH_OPTS = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
+                    def SSH_REMOTE = 'khagen@10.217.48.113'
+
+                    // No need to explicitly check the return code. The pipeline
+                    // will fail if sh returns a non 0 exit code
+                    sh """
+                        ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'mkdir -p ${SSH_DIR}'"
+                    """
+                    sh """
+                        ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'mkdir -p ${SSH_DIR}'"
+                    """
+                    sh """
+                        ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'find ${SSH_DIR} -type f -mtime +14 -exec rm -f {} \\;'"
+                    """
+                    sh """
+                        scp ${SSH_OPTS} build/vyos*.iso ${SSH_REMOTE}:${SSH_DIR}/
+                    """
+                }
+            }
         }
         cleanup {
             echo 'One way or another, I have finished'
-- 
cgit v1.2.3