#!/usr/bin/env groovy

pipeline {
    agent any
    options {
        timestamps()
        ansiColor('xterm')
    }  
    stages {
        stage('Build package') {
            steps {
                checkout scm
	        sh """
mkdir -p packer && cd packer
PACKER_VER=1.5.4
wget -q "https://releases.hashicorp.com/packer/\${PACKER_VER}/packer_\${PACKER_VER}_linux_amd64.zip"
unzip -o packer_\${PACKER_VER}_linux_amd64.zip
cd ..
export PATH=\$(pwd)/packer:\$PATH
packer build -color=false packer.json
	        """
            }
        }
        stage('Upload package') {
            environment {
                ARTI_CONFIG_FILE = credentials('dta_arti_creds')
            }
            steps {
                script {
                    if (env.BRANCH_NAME == 'master') {
                        sh 'arti -c $ARTI_CONFIG_FILE deb -o bionic wget*.deb'
                    } else {
                        sh 'arti -c $ARTI_CONFIG_FILE deb -o bionic -p testing wget*.deb'
                    }
                }
            }
        }
    }
}
