Created
December 8, 2021 14:22
-
-
Save boardstretcher/28e748c58fc2b95075381f3fd766925a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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