CI: added a job (pipeline) and step to publish artifacts to public server stx-8.0.0
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 15 Mar 2018 09:44:04 +0000
branchstx-8.0.0
changeset 223 575d0458b5c0
parent 222 80f098bd53ca
child 224 212ec423a6ab
CI: added a job (pipeline) and step to publish artifacts to public server ...using SFTP. This is separated into its own job (pipeline) to allow scheduling the upload for later since it may take a long time and saturate the internet connection.
ci/publish.groovy
ci/steps.groovy
rakelib/inifile.rb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ci/publish.groovy	Thu Mar 15 09:44:04 2018 +0000
@@ -0,0 +1,47 @@
+/*
+ * This is a publish pipeline
+ */
+
+
+pipeline {
+    agent any
+
+    parameters {
+        string(name: 'job', description: 'Job whose artifacts to upload',  defaultValue: 'stx_jv')
+        string(name: 'srv', description: 'Server (and username) where to upload artifacts',  defaultValue: "${env.STX_PUBLISH_SERVER}")
+        string(name: 'dir', description: 'Directory where to upload artifacts  ',  defaultValue: "${env.STX_PUBLISH_DIRECTORY}/6.2.6")
+    }
+
+    stages {
+        stage('Copy artifacts') {
+            steps {
+                copyArtifacts projectName: "${params.job}", selector: lastSuccessful(), excludes: '**/*prebuilt*'
+                sh "ls -al artifacts"
+            }
+        }
+
+        stage ( "Upload artifacts" ) {
+            steps {
+                sshagent([ "8be01219-a51e-410a-9850-bf9c134283fb" ]) {
+                    sh script:
+                        """
+                        sftp -b - ${params.srv} <<END
+                        cd ${params.dir}
+                        ls
+                        rm *
+                        put artifacts/*
+                        ls
+                        END
+                        """.stripIndent()
+                }
+            }
+        }
+        stage ( "Cleanup" ) {
+            steps {
+                cleanWs()
+            }
+        }
+    }
+}
+
+
--- a/ci/steps.groovy	Mon Mar 12 22:08:46 2018 +0000
+++ b/ci/steps.groovy	Thu Mar 15 09:44:04 2018 +0000
@@ -69,13 +69,14 @@
         matrix ( configurations ) {
             stage ( "Checkout - {${env.BUILD_TARGET}} " ) {
                 sshagent([ scm.getCredentialsId() ]) {
+                    branch_to_use = branch != null ? branch : scm.getBranch()
                     sh  """
                         if [ -f build.rb ]; then
                             hg pull --ssh ssh ${scm.getSource()}
                         else
                             hg clone --ssh ssh ${scm.getSource()} .
                         fi
-                        hg up ${branch != null ? branch : scm.getBranch()}
+                        hg up ${branch_to_use}
                         """
                     sh  "ruby build.rb --project \"stx:jv-branch\" --build-target ${env.BUILD_TARGET} update"
                 }
@@ -111,18 +112,12 @@
     }
 
     /*
-     * Build all artifacts - to allow Pocho to run full St/X without
+     * Build and publish all artifacts - to allow (beta) testers to run full St/X without
      * a need to build it itself
      */
-    // stage ( "Artifacts (stx & librun)")
-    // matrix ( configurations ) {
-    //     stage ( "Artifacts (stx & librun) - {${env.BUILD_TARGET}}") {
-    //         sh "ruby build.rb --project \"stx:jv-branch\" --build-target ${env.BUILD_TARGET} artifacts:prebuilt-stc"
-    //         sh "ruby build.rb --project \"stx:jv-branch\" --build-target ${env.BUILD_TARGET} artifacts:prebuilt-librun"
-    //         archiveArtifacts artifacts: "artifacts/*build${env.BUILD_NUMBER}*.zip, artifacts/*build${env.BUILD_NUMBER}*.bz2, artifacts/*build${env.BUILD_NUMBER}*.sha256", fingerprint: true//, onlyIfSuccessful: true
-    //     }
-    // }
     artifacts();
+    input(message: 'Publish artifacts?')
+    publish("8.0.0-rc")
 }
 
 /*
@@ -157,6 +152,31 @@
 }
 
 /*
+ * Publish built artifacts to download server
+ */
+def publish(dir) {
+    Calendar current = Calendar.getInstance()
+    Calendar scheduled = current.clone()
+
+    /*
+     * Schedule the upload to the next day, 3am in the morning
+     */
+    scheduled.add(Calendar.DATE, 1)
+    scheduled.set(Calendar.HOUR_OF_DAY, 3)
+
+    build(job:        'stx_jv_publish',
+          parameters: [
+                        string(name: 'job', value: env.JOB_NAME),
+                        string(name: 'srv', value: env.STX_PUBLISH_SERVER),
+                        string(name: 'dir', value: "${env.STX_PUBLISH_DIRECTORY}/${dir}")
+                      ],
+          quietPeriod: (scheduled.getTimeInMillis() - current.getTimeInMillis()) / 1000,
+          wait: false)
+}
+
+
+
+/*
  * Utility. Return true, if there are any changes to be pushed to an upstream,
  * false othervise.
  */
--- a/rakelib/inifile.rb	Mon Mar 12 22:08:46 2018 +0000
+++ b/rakelib/inifile.rb	Thu Mar 15 09:44:04 2018 +0000
@@ -88,7 +88,7 @@
       when @filename
         read
       else
-        puts 'Error happend during initialization'
+        merge!({})
     end
   end