Skip to content

Commit e4815b5

Browse files
author
R. Tyler Croy
committedSep 27, 2015
Merge pull request #376 from oloc/template
Add template in the jenkins::job
2 parents ce8b98b + 9e17fe1 commit e4815b5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
 

‎manifests/job.pp

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# path to a puppet file() resource containing the Jenkins XML job description
1212
# will override 'config' if set
1313
#
14+
# template
15+
# path to a puppet template() resource containing the Jenkins XML job description
16+
# will override 'config' if set
17+
#
1418
# jobname = $title
1519
# the name of the jenkins job
1620
#
@@ -23,6 +27,7 @@
2327
define jenkins::job(
2428
$config,
2529
$source = undef,
30+
$template = undef,
2631
$jobname = $title,
2732
$enabled = 1,
2833
$ensure = 'present',
@@ -42,6 +47,10 @@
4247
validate_string($source)
4348
$realconfig = file($source)
4449
}
50+
elsif $template {
51+
validate_string($template)
52+
$realconfig = template($template)
53+
}
4554
else {
4655
$realconfig = $config
4756
}

‎spec/defines/jenkins_job_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,25 @@
127127
it { should raise_error(Puppet::Error, /Must pass config/) }
128128
end
129129

130+
describe 'with templated config and blank regular config' do
131+
let(:thetemplate) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') }
132+
let(:params) {{ :ensure => 'present', :template => thetemplate, :config => '' }}
133+
it { should contain_file('/tmp/myjob-config.xml')\
134+
.with_content(/sourcedconfig/) }
135+
end
136+
137+
describe 'with templated config and regular config' do
138+
quotes = "<xml version='1.0' encoding='UTF-8'></xml>"
139+
let(:thetemplate) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') }
140+
let(:params) {{ :ensure => 'present', :template => thetemplate, :config => quotes }}
141+
it { should contain_file('/tmp/myjob-config.xml')\
142+
.with_content(/sourcedconfig/) }
143+
end
144+
145+
describe 'with templated config and no regular config' do
146+
let(:thetemplate) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/testjob.xml') }
147+
let(:params) {{ :ensure => 'present', :template => thetemplate }}
148+
it { should raise_error(Puppet::Error, /Must pass config/) }
149+
end
150+
130151
end

0 commit comments

Comments
 (0)