Class: JenkinsTaskManageJobs

Inherits:
JenkinsTask show all
Defined in:
lib/tasks/jenkins_task_manage_jobs.rb

Instance Method Summary collapse

Methods inherited from JenkinsTask

#config, #config_file, #fail_on_args_error, #fail_on_existing_job, #fail_on_missing_remote_branch, #fail_on_non_existing_job, #job, #project

Instance Method Details

#create_new_job(branch) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tasks/jenkins_task_manage_jobs.rb', line 4

def create_new_job(branch)
  configure unless config

  job_name = job(branch)
  puts "Creating new job #{job_name}"

  fail_on_args_error(branch)
  fail_on_missing_remote_branch(branch)
  fail_on_existing_job(job_name)

  rake_spec = "\nbundle exec rake spec"
  rake_jasmine = " && bundle exec rake jasmine"
  rake_cukes = " && bundle exec rake cukes"
  tar_file_name = "#{project}-#{branch}-${BUILD_NUMBER}.tar.gz"
  tar_file = "&& tar cvfz #{tar_file_name} --exclude-from=tarignore * .[a-zA-Z0-9]*"
  job_hash = {
    :name => job_name,
    :restricted_node => "#{config['jenkins']['restricted_node']}",
    :scm_provider => "git",
    :scm_url => "[email protected]:VodafoneAustralia/#{project}.git",
    :scm_branch => branch,
    :shell_command => "
      #!/bin/bash -e
      export TERM=xterm
      [[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"
      bundle package --all
      RAILS_ENV=test bundle exec rake

      bash script/createManifest
      cd ${WORKSPACE}/../
      rm -f ${JOB_NAME}.tar.gz
      tar --exclude=.git --exclude=lib/load_test --exclude=feature --exclude=coverage --exclude=log --exclude=build --exclude=spec -zcf ${JOB_NAME}.tar.gz ${JOB_NAME}
      aws s3api put-object --bucket vha-repository --key releases/paas/search-app/#{tar_file_name} --region ap-southeast-2 --body ${JOB_NAME}.tar.gz",
    :scm_branch => branch,
    :scm_trigger => '*/5 * * * *',
    :build_wrappers_xvfb => true,
    :build_wrappers_ansicolor => true,
    :build_wrappers_mask_password => true,
    :log_rotator => true
  }

  s3_options = config['s3_options'].merge({tar_file: tar_file_name})
  s3_options = Hash[s3_options.map { |k, v| [k.to_sym, v] }]
  git_options = { fast_remote_polling: true }
  job_hash.merge!(s3_artifact_publisher: s3_options, git: git_options)
  client.job.create_freestyle job_hash

  add_email_notification(job_name)

  puts "Done. New job #{job_name} created with SUCCESS"
end

#delete_job(branch) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tasks/jenkins_task_manage_jobs.rb', line 56

def delete_job(branch)
  job_name = job(branch)
  puts "Deleting job #{job_name}"

  fail_on_args_error(branch)
  fail_on_missing_remote_branch(branch)
  fail_on_non_existing_job(job_name)

  client.job.delete job_name

  puts "Done. Job #{job_name} has been deleted"
end

#get_job_config(branch) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/tasks/jenkins_task_manage_jobs.rb', line 69

def get_job_config(branch)
  job_name = job(branch)
  puts "Fetching configuration of job: #{job_name}"

  fail_on_args_error(branch)
  fail_on_missing_remote_branch(branch)
  fail_on_non_existing_job(job_name)

  puts "Done.\n#{client.job.get_config(job_name)}"
end