Skip to content

Instantly share code, notes, and snippets.

@boardstretcher
Created January 14, 2019 14:27
Show Gist options
  • Save boardstretcher/50bbbd55a43d3f2b12f928300fe4a44c to your computer and use it in GitHub Desktop.
Save boardstretcher/50bbbd55a43d3f2b12f928300fe4a44c to your computer and use it in GitHub Desktop.
#!/groovy
node('node1') {
stage('Syntax Testing') {
deleteDir()
checkout scm
try {
sh '/usr/local/bin/rubocop ./cookbooks --fail-level E -f s'
}
catch (Exception ex) {
mail from: "jenkins_admin@jenkins.dev.net",
to: "boardstretcher@github.com",
subject: "jenkins chef orchestration syntax check FAILED",
body: "syntax_testing section (rubocop)... build number: ${env.BUILD_NUMBER}"
throw ex
}
}
}
node('node1') {
stage('Stash Configs') {
deleteDir()
checkout scm
sh '/usr/local/bin/rubocop ./cookbooks --fail-level E -f s'
stash excludes: '**/.*,_vagrant/**', name: 'configs'
}
}
remote1: {
node('node2') {
stage('remote1') {
deleteDir()
unstash 'configs'
def work_dir = pwd()
// create knife.rb using the chef-jenkins identity key
withCredentials([[$class: 'FileBinding', credentialsId: 'chef-jenkins', variable: 'client_key']]) {
writeFile file: '.chef/knife.rb', text: """
log_level :info
log_location STDOUT
node_name 'jenkins'
client_key '${client_key}'
validation_client_name 'dev-validator'
validation_key '/etc/opscode/dev-validator.pem'
chef_server_url 'https://chef01.dev.net/organizations/local'
chef_repo_path '${work_dir}'
ssl_verify_mode :verify_none
"""
withCredentials([[$class: 'FileBinding', credentialsId: 'dev-databag-key', variable: 'dev_databag_key']]) {
parallel cookbooks: {
sh 'knife upload -c .chef/knife.rb cookbooks/'
}, data_bags: {
sh 'knife upload -c .chef/knife.rb data_bags/'
}, environments: {
sh 'knife upload -c .chef/knife.rb environments/'
}, roles: {
sh 'knife upload -c .chef/knife.rb roles/'
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment