Class: PdkSync::JenkinsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pdksync/jenkinsclient.rb

Instance Method Summary collapse

Constructor Details

#initialize(jenkins_server_url, jenkins_platform_access_settings) ⇒ JenkinsClient

Returns a new instance of JenkinsClient.

Parameters:

  • jenkins_platform_access_settings (String)

    The Jenkins credentials, required to access the Jenkins API



13
14
15
16
17
18
19
# File 'lib/pdksync/jenkinsclient.rb', line 13

def initialize(jenkins_server_url, jenkins_platform_access_settings)
  jenkins_username = jenkins_platform_access_settings[:jenkins_username]
  jenkins_password = jenkins_platform_access_settings[:jenkins_password]
  @client = JenkinsApi::Client.new('server_url' => jenkins_server_url,
                                   'username'   => jenkins_username,
                                   'password'   => jenkins_password)
end

Instance Method Details

#create_adhoc_job(github_repo, github_branch, github_user, job_name) ⇒ Object

Returns Build Id returned by the job.

Parameters:

  • github_repo (String)

    Repo or Module for which the adhoc job to be created

  • github_branch (String)

    The target branch against which to create the adhoc job

Returns:

  • Build Id returned by the job



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pdksync/jenkinsclient.rb', line 30

def create_adhoc_job(github_repo, github_branch, github_user, job_name)
  # params to start the build
  job_params = { 'GITHUB_USER' => github_user,
                 'GITHUB_REPO' => github_repo,
                 'GITHUB_REF'  => github_branch }
  # job name
  # Wait for up to 30 seconds, attempt to cancel queued build
  opts = { 'build_start_timeout' => 30,
           'cancel_on_build_start_timeout' => true,
           'completion_proc' => lambda { |build_number, cancelled| # rubocop:disable Style/Lambda
             if build_number
               PdkSync::Logger.info "Wait over: build #{build_number} started"
             else
               PdkSync::Logger.info "Wait over: build not started, build #{cancelled ? '' : 'NOT '} cancelled"
             end
           } }

  build_id = @client.job.build(job_name, job_params || {}, opts)
  build_id
end