Skip to content

Instantly share code, notes, and snippets.

@TJM
Last active October 25, 2018 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TJM/6617bc9cf76be0ea11c8b0c88a1f511d to your computer and use it in GitHub Desktop.
Save TJM/6617bc9cf76be0ea11c8b0c88a1f511d to your computer and use it in GitHub Desktop.
First (workable) attempt at using Pipeline for Puppet control-repo code testing and deployment - Uses the Mesos plugin to spin up slaves as "cloud1" and the Puppet Enterprise plugin for deployment https://wiki.jenkins.io/display/JENKINS/Puppet+Enterprise+Pipeline+Plugin
#!/usr/bin/env groovy
// NOTE:
// * This is designed to work as a Multi-Branch PIPELINE buid.
// * Our Jenkins Slave is mesos and labeled "cloud1" (you may need to adjust)
// * This uses the Puppet Enterprise Jenkins plugin. It assumes that is setup
// * Also there needs to be a credential (API KEY) with the id of "puppet"
pipeline {
//agent { label 'cloud1' }
agent {
docker {
label 'cloud1'
image 'puppet/puppet-dev-tools:latest'
}
}
options {
timeout(time: 10, unit: 'MINUTES')
timestamps()
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '50', daysToKeepStr: '30'))
}
stages {
stage('tests') {
failFast false
parallel {
// Skipping PDK for now, the container doesn't have all the gems, so it takes longer
// stage('pdk validate') {
// steps {
// //sh 'pdk validate puppet'
// }
// }
stage('puppet-code') {
steps {
sh 'puppet-lint .'
sh 'puppet parser validate .'
}
}
stage('Puppetfile') {
steps {
sh 'r10k puppetfile check Puppetfile'
sh 'r10k puppetfile check style Puppetfile'
}
}
stage('yaml-lint') {
steps {
sh 'gem install yaml-lint'
sh 'yaml-lint data'
}
}
// stage('pdk test') {
// steps {
// sh '''
// pdk test unit
// '''
// }
// }
// stage('onceover') {
// steps {
// sh '''
// onceover -???
// '''
// }
// }
}
}
stage('deploy') {
options { skipDefaultCheckout() }
steps{
script {
puppet.credentials 'puppet'
puppet.codeDeploy BRANCH_NAME
}
}
}
// stage('run in dev') {
// // only run in dev
// when {
// expression { DEPLOY_BRANCH == 'development' }
// }
// options { skipDefaultCheckout() }
// steps {
// script {
// puppet.job 'development', query: 'nodes { catalog_environment = "development" }'
// }
// }
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment