diff --git a/manifests/job.pp b/manifests/job.pp index 6568b82c3..ebc0252ef 100644 --- a/manifests/job.pp +++ b/manifests/job.pp @@ -7,6 +7,10 @@ # config # the content of the jenkins job config file (required) # +# source +# path to a puppet file() resource containing the Jenkins XML job description +# will override 'config' if set +# # jobname = $title # the name of the jenkins job # @@ -18,6 +22,7 @@ # define jenkins::job( $config, + $source = undef, $jobname = $title, $enabled = 1, $ensure = 'present', @@ -28,8 +33,16 @@ jobname => $jobname, } } else { + if $source { + validate_string($source) + $realconfig = file($source) + } + else { + $realconfig = $config + } + jenkins::job::present { $title: - config => $config, + config => $realconfig, jobname => $jobname, enabled => $enabled, } diff --git a/spec/defines/jenkins_job_spec.rb b/spec/defines/jenkins_job_spec.rb index f8d8bd6c9..eb8f994c2 100644 --- a/spec/defines/jenkins_job_spec.rb +++ b/spec/defines/jenkins_job_spec.rb @@ -93,4 +93,25 @@ .with_content('the dog said "woof"') } end + describe 'with sourced config and blank regular config' do + let(:thesource) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') } + let(:params) {{ :ensure => 'present', :source => thesource, :config => '' }} + it { should contain_file('/tmp/myjob-config.xml')\ + .with_content(/sourcedconfig/) } + end + + describe 'with sourced config and regular config' do + quotes = "" + let(:thesource) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') } + let(:params) {{ :ensure => 'present', :source => thesource, :config => quotes }} + it { should contain_file('/tmp/myjob-config.xml')\ + .with_content(/sourcedconfig/) } + end + + describe 'with sourced config and no regular config' do + let(:thesource) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') } + let(:params) {{ :ensure => 'present', :source => thesource }} + it { should raise_error(Puppet::Error, /Must pass config/) } + end + end diff --git a/spec/fixtures/testjob.xml b/spec/fixtures/testjob.xml new file mode 100644 index 000000000..38c635ed7 --- /dev/null +++ b/spec/fixtures/testjob.xml @@ -0,0 +1 @@ +sourcedconfig