Skip to content

Instantly share code, notes, and snippets.

@boardstretcher
Created December 8, 2021 14:22
Show Gist options
  • Save boardstretcher/28e748c58fc2b95075381f3fd766925a to your computer and use it in GitHub Desktop.
Save boardstretcher/28e748c58fc2b95075381f3fd766925a to your computer and use it in GitHub Desktop.
pipeline {
agent {
label 'packerhost'
}
parameters {
string(name: 'AUSER', defaultValue: 'proofOFconcept', description: 'username')
string(name: 'APASS', defaultValue: 'proofOFconcept', description: 'password')
string(name: 'DEPLOY_ENV', defaultValue: 'DEV', description: 'deploy to environment')
}
environment {
PACKER_LOG = 1
BASEDIR = 'vmware-stage0'
BUILDFILE = 'vmware.pkr.hcl'
VARFILE = 'vmware.pkrvar.hcl'
USERFILE = 'variables.pkr.hcl'
}
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '5'))
timeout(time: 4, unit: 'HOURS')
timestamps()
}
stages {
stage('Initialize') {
steps {
deleteDir()
checkout scm
dir ("./${env.BASEDIR}/") {
sh "echo start [${env.STAGE_NAME}]"
sh "/usr/bin/packer init ./${env.BUILDFILE}"
sh "echo end [${env.STAGE_NAME}]"
}
}
}
stage('Validate') {
steps {
dir ("./${env.BASEDIR}/") {
sh "echo start [${env.STAGE_NAME}]"
// sh '/usr/bin/packer validate -syntax-only -var-file="${env.VARFILE}" .'
sh "echo end [${env.STAGE_NAME}]"
}
}
}
stage('DEV-PreBuild') {
when {
expression {
return params.DEPLOY_ENV == 'DEV'
}
}
steps {
dir ("./${env.BASEDIR}/") {
sh "echo start [${env.STAGE_NAME}]"
sh 'printenv'
sh "cat ${env.USERFILE}"
sh "cat ${env.VARFILE}"
sh "echo end [${env.STAGE_NAME}]"
}
}
}
stage('Build') {
steps {
dir ("./${env.BASEDIR}/") {
sh "echo start [${env.STAGE_NAME}]"
sh '/usr/bin/packer build -var-file="vmware.pkrvar.hcl" .'
sh "echo end [${env.STAGE_NAME}]"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment