Project

General

Profile

Revision ee96cf71

Added by Ondřej Pražák almost 6 years ago

Fixes #15329 - Add custom timeout for jenkins instance

View differences:

app/assets/javascripts/foreman_pipeline/jenkins-instances/details/views/jenkins-instance-details-info.html
32 32
      </span>
33 33
    </div>
34 34

  
35
    <div class="detail">
36
      <span class="info-label" translate>Timeout&nbsp;
37
          <i class="fa fa-question-circle"
38
             tooltip="{{ 'Time in minutes we are willing to wait before build on Jenkins starts' | translate }}"
39
             tooltip-animation="false"
40
             tooltip-append-to-body="true">
41
          </i>
42
      </span>
43
      <span class="info-value"
44
            bst-edit-custom="jenkinsInstance.timeout"
45
            on-save="save(jenkinsInstance)">
46
        <div class="form input">
47
          <input ng-model="jenkinsInstance.timeout"
48
                 name="timeout"
49
                 type="number"
50
                 min="1"/>
51
        </div>
52
      </span>
53
    </div>
54

  
35 55
  </section>
36 56
</div>
37

  
38 57
<div class="fr">
39 58
  <button class="btn btn-default" ng-click="checkJenkins()" ng-disabled="working">
40 59
      <i class="fa fa-wrench" ng-hide="working"></i>
app/assets/javascripts/foreman_pipeline/jenkins-instances/new/views/new-jenkins-instance-form.html
15 15
           name="url"
16 16
           ng-model="jenkinsInstance.url"
17 17
           type="text"
18
           tabindex="2"           
18
           tabindex="2"
19 19
           required/>
20 20
  </div>
21
  <div bst-form-group>   
21
  <div bst-form-group>
22 22
    <p class="alert alert-info" translate>
23 23
      Make sure to specify the port Jenkins master is running on. Example: http://jenkins.example.com:8080
24
    </p>     
24
    </p>
25 25
  </div>
26 26

  
27 27
  <div bst-form-group label="{{ 'Jenkins Home' | translate }}">
......
42 42
           required/>
43 43
  </div>
44 44

  
45
  <div bst-form-group label="{{ 'Timeout' | translate }}">
46
    <input id="timeout"
47
           name="timeout"
48
           ng-model="jenkinsInstance.timeout"
49
           type="number"
50
           min="1"
51
           tabindex="5" />
52
  </div>
53

  
54
  <div bst-form-group>
55
    <p class="alert alert-info" translate>
56
      Time in minutes we are willing to wait before build on Jenkins starts.
57
    </p>
58
  </div>
59

  
45 60
  <div bst-form-buttons
46 61
        on-cancel="transitionBack()"
47 62
        on-save="createJenkinsInstance(jenkinsInstance)"
app/controllers/foreman_pipeline/api/jenkins_instances_controller.rb
115 115
    end
116 116

  
117 117
    def jenkins_instance_params
118
      params.require(:jenkins_instance).permit(:name, :url, :jenkins_home, :cert_path)
118
      params.require(:jenkins_instance).permit(:name, :url, :jenkins_home, :cert_path, :timeout)
119 119
    end
120 120
  end
121 121
end
app/lib/actions/foreman_pipeline/jenkins/build.rb
5 5
      class Build < AbstractJenkinsAction
6 6

  
7 7
        def run
8
          # are we willing to wait longer than 30 mins until build starts?
9
          output[:build_num] = job.jenkins_instance.client.job.build(jenkins_project.name, params, 'build_start_timeout' => (30 * 60))
8
          timeout = job.jenkins_instance.timeout_sec
10 9
          output[:project_name] = jenkins_project.name
11 10
          output[:build_params] = params
11
          output[:build_num] = job.jenkins_instance.client.job.build(jenkins_project.name, params, 'build_start_timeout' => timeout)
12
        rescue => e
13
          fail "Jenkins build for #{jenkins_project.name} failed to start in a timely manner."
12 14
        end
13 15

  
14 16
        def params
......
17 19
          template_binding project_params
18 20
        end
19 21

  
22
        def rescue_strategy_for_self
23
          Dynflow::Action::Rescue::Skip
24
        end
25

  
20 26
        def template_binding(project_params)
21 27
          host = input[:data][:host]
22 28
          activation_key = input[:data][:activation_key]
......
32 38
      end
33 39
    end
34 40
  end
35
end
41
end
app/lib/actions/foreman_pipeline/jenkins/build_project.rb
16 16

  
17 17
        def run
18 18
          output[:status] = input[:build_status]
19
          output[:name] = input[:name]
20
          fail "Build on Jenkins failed for #{output[:name]}" unless output[:build_status] == "SUCCESS"
19 21
        end
20 22

  
21 23
        def rescue_strategy_for_self
app/lib/actions/foreman_pipeline/jenkins/bulk_build.rb
17 17
            trigger(BuildProject, input[:opts].merge({:project_id => project.id, :project_name => project.name}))
18 18
          end
19 19
        end
20

  
21
        def check_for_errors!
22
          # Do nothing. Just wait for all builds to finish and gather results
23
        end
20 24
      end
21 25
    end
22 26
  end
app/lib/actions/foreman_pipeline/mixins/uri_extension.rb
6 6
        require 'uri'
7 7

  
8 8
        def jenkins_hostname(job)
9
          URI(job.jenkins_instance.url).host  
9
          URI(job.jenkins_instance.url).host
10 10
        end
11 11
      end
12 12
    end
app/models/foreman_pipeline/jenkins_instance.rb
15 15
    FILEPATH_REGEX = /\A(\/|~)[a-z0-9\-_.\/]*[^\/]\z/i
16 16

  
17 17
    validates :name, :presence => true
18
    validates :cert_path, :format => {:with => FILEPATH_REGEX }
19
    validates :url, :uniqueness => true, :format => { :with => /\A(http|https):\/\/\S+:\d{1,4}\z/}
18
    validates :timeout, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }
19
    validates :cert_path, :format => { :with => FILEPATH_REGEX }
20
    validates :url, :uniqueness => true, :format => { :with => /\A(http|https):\/\/\S+:\d{1,4}\z/ }
20 21
    validates :organization, :presence => true
21 22
    validates :jenkins_home, :format => { :with => FILEPATH_REGEX }
22 23

  
......
35 36
      @client
36 37
    end
37 38

  
39
    def timeout_sec
40
      timeout * 60
41
    end
42

  
38 43
    private
39 44

  
40 45
    def authenticated_client(username, password, hash_args)
......
47 52
      return JenkinsApi::Client.new(hash_args) if username.nil?
48 53
      authenticated_client username, password, hash_args
49 54
    end
50

  
51 55
  end
52
end
56
end
app/views/foreman_pipeline/api/jenkins_instances/show.json.rabl
1 1
object @resource
2 2

  
3
attributes :id, :name, :url, :organization_id, :server_version, :jenkins_home, :cert_path
3
attributes :id, :name, :url, :organization_id, :server_version, :jenkins_home, :cert_path, :timeout
4 4

  
5 5
child :jenkins_user => :jenkins_user do
6 6
  extends "foreman_pipeline/api/jenkins_users/show"
db/migrate/20160629085119_add_timeout_to_jenkins_instance.rb
1
class AddTimeoutToJenkinsInstance < ActiveRecord::Migration
2
  def up
3
    add_column :foreman_pipeline_jenkins_instances, :timeout, :integer, :default => 60
4
  end
5

  
6
  def down
7
    remove_column :foreman_pipeline_jenkins_instances, :timeout
8
  end
9
end

Also available in: Unified diff