Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add always_build flag to PollingScheduler

Allows forcing of builds on a schedule even if there are no SCM changes
  • Loading branch information...
commit ac38eeda532b34a60364cc02ab7b9ed8822a695d 1 parent 6d3f2e2
@thewoolleyman thewoolleyman authored
View
7 app/models/polling_scheduler.rb
@@ -1,6 +1,7 @@
# PollingScheduler is a build scheduler that checks the given project's status one per polling
# interval to determine whether or not it should kick off a new build.
class PollingScheduler
+ attr_accessor :always_build
def initialize(project)
@project = project
@@ -25,7 +26,11 @@ def run
def check_build_request_until_next_polling
time_to_go = Time.now + polling_interval
while Time.now < time_to_go
- @project.build_if_requested
+ if @always_build
+ @project.force_build("Forcing build because project has 'always_build' flag set.")
+ else
+ @project.build_if_requested
+ end
sleep build_request_checking_interval
end
end
View
4 app/models/project.rb
@@ -326,6 +326,10 @@ def build_if_requested
end
end
+ def force_build(message = 'Build was forced')
+ build(source_control.latest_revision, [message, source_control.latest_revision.to_s])
+ end
+
def update_project_to_revision(build, revision)
if do_clean_checkout?
File.open(build.artifact('source_control.log'), 'w') do |f|
View
9 config/cruise_config.rb.example
@@ -18,8 +18,11 @@ Project.configure do |project|
# Ping Subversion for new revisions every 5 minutes (default: 30 seconds)
# project.scheduler.polling_interval = 5.minutes
-
- # Force the project to build once in every given time interval
+
+ # Force the project always build once every day and always build whether there are source control changes or not
+ # project.scheduler.polling_interval = 1.day
+ # project.scheduler.always_build = true
+
+ # Force the project to check for source control changes every given time interval, but NOT build if there are no changes
# project.triggered_by ScheduledBuildTrigger.new(project, :build_interval => 5.minutes, :start_time => 2.minutes.from_now)
-
end
View
12 test/unit/polling_scheduler_test.rb
@@ -54,4 +54,16 @@ def test_should_return_flag_to_reload_project_if_configurations_modified
assert_throws(:reload_project) { @scheduler.run }
end
+
+ def test_should_always_build_if_always_build_is_set
+ @scheduler.expects(:polling_interval).returns(1.seconds)
+ @scheduler.stubs(:build_request_checking_interval).returns(0)
+ Time.expects(:now).times(3).returns(Time.at(0), Time.at(0), Time.at(2))
+
+ @mock_project.expects(:build_if_requested).times(0)
+ @mock_project.expects(:force_build).times(1)
+
+ @scheduler.always_build = true
+ @scheduler.check_build_request_until_next_polling
+ end
end
View
9 test/unit/project_test.rb
@@ -424,6 +424,15 @@ def test_build_if_requested_should_specify_build_requested_reason
end
end
+ def test_force_build
+ in_sandbox do |sandbox|
+ @project.path = sandbox.root
+ revision = @project.source_control.add_revision :message => "A super special feature", :number => 1
+ @project.expects(:build).with(revision, ['Custom message.', '1: A super special feature'])
+ @project.force_build('Custom message.')
+ end
+ end
+
def test_build_requested
@project.stubs(:path).returns("a_path")
File.expects(:file?).with(@project.build_requested_flag_file).returns(true)
Please sign in to comment.
Something went wrong with that request. Please try again.