Class: JenkinsPipelineBuilder::Promotion
- Inherits:
-
Object
- Object
- JenkinsPipelineBuilder::Promotion
- Defined in:
- lib/jenkins_pipeline_builder/promotion.rb
Instance Method Summary collapse
- #create(params, job_name) ⇒ Object
-
#initialize(generator) ⇒ Promotion
constructor
A new instance of Promotion.
- #local_output(xml) ⇒ Object
- #out_dir ⇒ Object
- #prom_to_xml(params) ⇒ Object
Constructor Details
#initialize(generator) ⇒ Promotion
Returns a new instance of Promotion.
25 26 27 28 29 |
# File 'lib/jenkins_pipeline_builder/promotion.rb', line 25 def initialize(generator) @generator = generator @client = generator.client @logger = @client.logger end |
Instance Method Details
#create(params, job_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jenkins_pipeline_builder/promotion.rb', line 31 def create(params, job_name) success, payload = prom_to_xml(params) return success, payload unless success xml = payload return local_output(xml) if JenkinsPipelineBuilder.debug || JenkinsPipelineBuilder.file_mode @client.get_config(get_process_path(job_name, params[:name])) @client.post_config(set_process_path(job_name, params[:name]), xml) rescue JenkinsApi::Exceptions::NotFound @client.post_config(init_process_path(job_name, params[:name]), xml) end |
#local_output(xml) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/jenkins_pipeline_builder/promotion.rb', line 55 def local_output(xml) JenkinsPipelineBuilder.logger.info 'Will create promotion' JenkinsPipelineBuilder.logger.info xml.to_s if @debug xml.to_s if @debug FileUtils.mkdir_p(out_dir) unless File.exist?(out_dir) File.open("#{out_dir}/promotion_debug.xml", 'w') { |f| f.write xml } xml end |
#out_dir ⇒ Object
64 65 66 |
# File 'lib/jenkins_pipeline_builder/promotion.rb', line 64 def out_dir 'out/xml' end |
#prom_to_xml(params) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jenkins_pipeline_builder/promotion.rb', line 43 def prom_to_xml(params) builder = Nokogiri::XML::Builder.new do |xml| xml.send('hudson.plugins.promoted__builds.PromotionProcess', 'plugin' => '[email protected]') do xml.buildSteps xml.conditions end end @n_xml = builder.doc JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml) [true, @n_xml.to_xml] end |