Class: WinCI::Job
- Inherits:
-
Object
- Object
- WinCI::Job
- Defined in:
- lib/winci/job.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
Instance Method Summary collapse
- #create(server = '127.0.0.1', port = '3010') ⇒ Object
- #get_build_sha(build) ⇒ Object
-
#initialize(project_name = 'files', config = std_config) ⇒ Job
constructor
A new instance of Job.
- #last_successful_build ⇒ Object
- #last_successful_build_sha ⇒ Object
- #provide_build(build = last_successful_build_sha, environments = ['production']) ⇒ Object
- #std_config ⇒ Object
Constructor Details
#initialize(project_name = 'files', config = std_config) ⇒ Job
Returns a new instance of Job.
10 11 12 13 |
# File 'lib/winci/job.rb', line 10 def initialize(project_name='files', config=std_config) @project_name = project_name @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/winci/job.rb', line 8 def config @config end |
#project_name ⇒ Object
Returns the value of attribute project_name.
8 9 10 |
# File 'lib/winci/job.rb', line 8 def project_name @project_name end |
Instance Method Details
#create(server = '127.0.0.1', port = '3010') ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/winci/job.rb', line 26 def create server='127.0.0.1', port='3010' Jenkins::Api.setup_base_url(:host => server, :port => port) if Jenkins::Api.create_job(name=@project_name, @config, = {:override => true}) == true return "#{@project_name} project created on jenkins" else raise "#{@project_name} project not created, something gone wrong or it already exist" end end |
#get_build_sha(build) ⇒ Object
40 41 42 43 44 |
# File 'lib/winci/job.rb', line 40 def get_build_sha build # Retrieve information about the actual build, and grab the last built revision out of it build_info = Jenkins::Api.get("/job/#{@project_name}/#{build["number"]}/api/json") build_info['actions'].detect { |h| h["lastBuiltRevision"] }["lastBuiltRevision"]["SHA1"] end |
#last_successful_build ⇒ Object
36 37 38 |
# File 'lib/winci/job.rb', line 36 def last_successful_build Jenkins::Api.job(@project_name)["lastSuccessfulBuild"] end |
#last_successful_build_sha ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/winci/job.rb', line 46 def last_successful_build_sha if last_successful_build return get_build_sha last_successful_build else raise 'There is none successful build yet!' end end |
#provide_build(build = last_successful_build_sha, environments = ['production']) ⇒ Object
54 55 56 |
# File 'lib/winci/job.rb', line 54 def provide_build(build=last_successful_build_sha, environments=['production']) # TODO provide this build to selected environments end |
#std_config ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/winci/job.rb', line 15 def std_config Jenkins::JobConfigBuilder.new(:ruby) do |c| c.scm = "C:/repos/files.git" c.steps = [ [:build_bat_step, "bundle exec rake"], [:build_bat_step, "git push C:/repos/production/files.git HEAD:master"] ] end end |