Skip to content

Commit

Permalink
Merge pull request #290 from gdhbashton/sourced-xml-jobs
Browse files Browse the repository at this point in the history
Support getting external .xml job descriptions
  • Loading branch information
R. Tyler Croy committed May 6, 2015
2 parents b8e2dbf + a422400 commit 7a5ada7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 14 additions & 1 deletion manifests/job.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -18,6 +22,7 @@
#
define jenkins::job(
$config,
$source = undef,
$jobname = $title,
$enabled = 1,
$ensure = 'present',
Expand All @@ -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,
}
Expand Down
21 changes: 21 additions & 0 deletions spec/defines/jenkins_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,25 @@
.with_content('<config>the dog said "woof"</config>') }
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 = "<xml version='1.0' encoding='UTF-8'></xml>"
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
1 change: 1 addition & 0 deletions spec/fixtures/testjob.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<config>sourcedconfig</config>

0 comments on commit 7a5ada7

Please sign in to comment.