From b3ec80e8a1268bc18ff4ad4682daa10d8e8f4e71 Mon Sep 17 00:00:00 2001 From: Hubert Huang Date: Tue, 4 Nov 2014 01:09:43 -0800 Subject: [PATCH] Add job params to configure scm trigger --- lib/jenkins_api_client/job.rb | 13 +++++++++---- spec/unit_tests/job_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/jenkins_api_client/job.rb b/lib/jenkins_api_client/job.rb index 6b5573f0..5c5bfe31 100644 --- a/lib/jenkins_api_client/job.rb +++ b/lib/jenkins_api_client/job.rb @@ -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 diff --git a/spec/unit_tests/job_spec.rb b/spec/unit_tests/job_spec.rb index f3b4b678..7d63aa5b 100644 --- a/spec/unit_tests/job_spec.rb +++ b/spec/unit_tests/job_spec.rb @@ -645,6 +645,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