[releng] A pipeline to promote a build to download.eclipse.org

Change-Id: Idb1cd4e4389b9dcc3afcc69b9ae96ca8dbbc87ee
Signed-off-by: Jonah Graham <jonah@kichwacoders.com>
diff --git a/releng/org.eclipse.ptp.jenkins/promote-build.Jenkinsfile b/releng/org.eclipse.ptp.jenkins/promote-build.Jenkinsfile
new file mode 100644
index 0000000..49b130a
--- /dev/null
+++ b/releng/org.eclipse.ptp.jenkins/promote-build.Jenkinsfile
@@ -0,0 +1,19 @@
+pipeline {
+  agent any
+  parameters {
+    booleanParam(defaultValue: true, description: 'Do a dry run of the build. All commands will be echoed.First run with this on, then when you are sure it is right, choose rebuild in the passing job and uncheck this box', name: 'DRY_RUN')
+    string(defaultValue: 'updates/photon', description: 'The relative path in PTP downloads area to publish promoted build to (e.g. updates/photon, builds/photon/milestones/2019-09-M1, builds/remote/photon/milestones/2019-09-M1)', name: 'PTP_PUBLISH_LOCATION')
+    choice(choices: ['ptp', 'remote', 'photran'], description: 'The PTP project name being promoted from (e.g. ptp, remote). The CI job will be $PROJECT-build', name: 'PROJECT')
+    string(defaultValue: '12345', description: 'The CI build number being promoted from', name: 'PTP_BUILD_NUMBER')
+  }
+  stages {
+    stage('Upload') {
+      steps {
+        sshagent ( ['projects-storage.eclipse.org-bot-ssh']) {
+          git branch: 'master', url: 'git://git.eclipse.org/gitroot/ptp/org.eclipse.ptp.git'
+          sh './releng/org.eclipse.ptp.jenkins/promote-build.sh'
+        }
+      }
+    }
+  }
+}
diff --git a/releng/org.eclipse.ptp.jenkins/promote-build.sh b/releng/org.eclipse.ptp.jenkins/promote-build.sh
new file mode 100755
index 0000000..1b92fbc
--- /dev/null
+++ b/releng/org.eclipse.ptp.jenkins/promote-build.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+set -u # run with unset flag error so that missing parameters cause build failure
+set -e # error out on any failed commands
+set -x # echo all commands used for debugging purposes
+
+SSH="ssh genie.ptp@projects-storage.eclipse.or"
+DOWNLOAD=download.eclipse.org/tools/ptp/$PTP_PUBLISH_LOCATION
+DOWNLOAD_MOUNT=/home/data/httpd/$DOWNLOAD
+ARTIFACTS=https://ci.eclipse.org/ptp/job/${PROJECT}-build/$PTP_BUILD_NUMBER/artifact/
+
+if [ "$PROJECT" == "ptp" ]; then
+    ARTIFACTS_REPO_TARGET=$ARTIFACTS/releng/org.eclipse.ptp.repo/target
+elif [ "$PROJECT" == "remote" ]; then
+    ARTIFACTS_REPO_TARGET=$ARTIFACTS/releng/org.eclipse.remote.repo/target
+elif [ "$PROJECT" == "photran" ]; then
+    ARTIFACTS_REPO_TARGET=$ARTIFACTS/org.eclipse.photran.repo/target
+else
+    echo "Missing repo location of $PROJECT"
+    exit 1
+fi
+
+echo Using download location root of "https://$DOWNLOAD"
+echo Using artifacts location root of $ARTIFACTS
+
+echo Testing to make sure we are publishing to a new directory
+$SSH "test ! -e $DOWNLOAD_MOUNT"
+
+echo Testing to make sure artifacts location is sane
+wget -q --output-document=/dev/null $ARTIFACTS_REPO_TARGET
+
+ECHO=echo
+if [ "$DRY_RUN" == "false" ]; then
+    ECHO=""
+else
+    echo Dry run of build:
+fi
+
+$ECHO $SSH "mkdir -p $DOWNLOAD_MOUNT"
+
+$ECHO $SSH "cd $DOWNLOAD_MOUNT && \
+    wget -q $ARTIFACTS_REPO_TARGET/repository/*zip*/repository.zip && \
+    unzip -q repository.zip && \
+    mv repository/* . && \
+    rm -r repository repository.zip"
+
+if [ "$DRY_RUN" == "false" ]; then
+    echo Release uploaded to "https://$DOWNLOAD"
+else
+    echo Dry run completed.
+fi