Skip to content

Commit

Permalink
Merge pull request #157 from hubert/feature/scm-triggers
Browse files Browse the repository at this point in the history
Add job params to configure scm trigger
  • Loading branch information
arangamani committed Nov 13, 2014
2 parents 2ec1944 + b3ec80e commit e5203a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/jenkins_api_client/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,19 @@ def build_freestyle_config(params)
"#{params[:block_build_when_downstream_building]}")
xml.blockBuildWhenUpstreamBuilding(
"#{params[:block_build_when_upstream_building]}")
if params[:timer]
xml.triggers.vector do
xml.triggers.vector do
if params[:timer]
xml.send("hudson.triggers.TimerTrigger") do
xml.spec params[:timer]
end
end
else
xml.triggers.vector

if params[:scm_trigger]
xml.send("hudson.triggers.SCMTrigger") do
xml.spec params[:scm_trigger]
xml.ignorePostCommitHooks params.fetch(:ignore_post_commit_hooks) { false }
end
end
end
xml.concurrentBuild "#{params[:concurrent_build]}"
# Shell command stuff
Expand Down
23 changes: 23 additions & 0 deletions spec/unit_tests/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,29 @@
expect(@job.plugin_collection).to receive(:configure).and_return(Nokogiri::XML::Document.new(''))
@job.build_freestyle_config(name: 'foobar')
end

context 'scm_trigger and ignore_post_commit_hooks params' do
it 'configures triggers with a hudson.triggers.SCMTrigger' do
xml = @job.build_freestyle_config(
name: 'foobar',
scm_trigger: 'H 0 29 2 0',
ignore_post_commit_hooks: true
)

xml_config = Nokogiri::XML(xml)
expect(xml_config.at_css('triggers spec').content).to eql('H 0 29 2 0')
expect(xml_config.at_css('triggers ignorePostCommitHooks').content).to eql('true')
end

it 'does not add a tag to triggers if not passed scm_trigger param' do
xml = @job.build_freestyle_config(
name: 'foobar'
)

xml_config = Nokogiri::XML(xml)
expect(xml_config.at_css('triggers').children).to be_empty
end
end
end

context 'plugin settings' do
Expand Down

0 comments on commit e5203a6

Please sign in to comment.