How to configure jenkins via chefzero vagrant provisioner

chefJenkinsvagrant

using the jenkins cookbook 2.2.2

==> https://supermarket.chef.io/cookbooks/jenkins

i can bring up jenkins in vagrant vm using chef_zero provisioner with


chef.run_list = [
'recipe[jenkins::master]',
]

however, i am trying to install plugins and create a new job from erb template, and i am having no luck. my understanding is that configuration should be passed using the "chef.json" datastructure with chef zero. I have tried many many syntax configurations, but no luck (and no error, as it appears if not correct, it is just ignored)

here is an example of installing a plugin that is not working (i guess the question is how does one configure a chef resource within a recipe inside of vagrant with chef_zero provision):


chef.json = {
'java' => {
'jdk_version' => '7',
},
'jenkins' => {
'master' => {
'jenkins_plugin' => [ 'job-dsl', 'groovy', 'git', 'packer' ]
}
}
}

i would be very grateful if anyone could provide a working example of the chef.json that vagrant chef_zero provisioner wants to install jenkins plugin (and/or installing a new job from erb template or xml file)

Best Answer

the answer is plugins and jobs cannot be directly invoked by the community jenkins cookbook. a wrapper cookbook needs to be made (which depends on jenkins).

this is done by creating a blank cookbook: knife cookbook create jenkins_wrapper

adding community cookbook dependancy (jenkins_wrapper/metadata.rb): depends 'jenkins'

and then making it do something (jenkins_wrapper/recipes/default.rb): jenkins_plugin 'git' jenkins_plugin 'job-dsl'

additionally, if using berkshelf, you must add path to cookbook in Berksfile: cookbook 'jenkins_wrapper', path: '/path/to/jenkins_wrapper' (this path can be relative)

it took me a few hours to figure this all out, so hopefully this will help someone else save some time

Related Topic