Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build version number support on pre-post 1.519 Jenkins, plus callbacks while waiting #106

Merged
merged 8 commits into from
Nov 15, 2013

Conversation

dougforpres
Copy link
Contributor

Hi

This is a port of some code we were using internally to get a better result when waiting for a queued build to start.

The prior 'wait for build number' would work only on 1.519+ versions of Jenkins, and would silently block while it was waiting. Our need was for a more 'chatty' wait, so we added the (optional) callbacks.

This push includes code to auto pull the Jenkins and Hudson version numbers on every request, so additional requests do not need to be made to determine version number. There are also some utility methods to compare two version strings and return -1, 0, +1 based on older, same, newer.

The build method still supports the previous true/false for param 3, but now accepts a hash of options.
The options include:

  • how long to wait for build to start (if not specified, same as old 'false' param) - default OFF
  • whether to attempt cancel of queued job if timeout occurs - default NO
  • how often to poll - default 2 seconds
  • callback for wait progress - default nil
  • callback for 'build' start/fail - default nil

Returns same as it used to, and raises Timeout::Error as it used to.

Determines whether it can use 'queue' object to monitor job-wait, or whether it has to use older 'get job status' method (which raises NotFound if job hasn't started) automatically, and behavior is identical regardless of the Jenkins version.

caveat: the 'cancel' option has no effect on older Jenkins.

unit/func tests included

Regards
Doug

dougforpres and others added 6 commits October 9, 2013 12:09
… add support for version number deconstruction and comparison
…uild-queue progress and optional auto-cancel if build doesn't start within timeout period (for Jenkins post 1.519 release).

Retained backward compatibility with previous build method through check of Hash or True/False in 3rd param
@dougforpres
Copy link
Contributor Author

That build failure seems outside the scope of my changes

@arangamani
Copy link
Owner

I know the build failure issue. Don't worry about it.

# v 1.2 is a lot older than v 1.102 - and simple < > on version
# strings doesn't work so well
def deconstruct_version_string(version)
match = version.match(/^(\d+)\.(\d+)$/)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that people use LTS releases of Jenkins. The recent LTS release for Jenkins is 1.509.4. In this case this can't match the version correctly. So a patch version should be added to this logic along with major and minor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, was unaware of that - I had taken a quick squiz at the versions and had not seen the 3 parter.
Will definitely fix!

@dougforpres
Copy link
Contributor Author

Not trying to rush you or anything, but have you had a chance to take a deeper look at this?
Let me know if there are any concerns, questions, or other tweaks you may have.

@arangamani
Copy link
Owner

I was looking at that. When running functional tests the node creation started failing because of a recent change in Jenkins and started thinking whether we need to support all versions of Jenkins or not. I'll keep you posted.

# successfully removed from build-queue
#
# @return [Integer] build number, or nil if not started (if timeout specified)
# [Response] http response code (per prev. behavior) (no timeout specified)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation of this method doesn't look good when generated with yard. Could you take a look?

@arangamani
Copy link
Owner

I really appreciate your patience 😃

arangamani added a commit that referenced this pull request Nov 15, 2013
Build version number support on pre-post 1.519 Jenkins, plus callbacks while waiting
@arangamani arangamani merged commit 94bd8b1 into arangamani:master Nov 15, 2013
sebastianludwig pushed a commit to sebastianludwig/jenkins_api_client that referenced this pull request Nov 28, 2013
NameError: undefined local variable or method `expected_build_number' for #<JenkinsApi::Client::Job>
	from /Users/Sebastian/.rvm/gems/ruby-1.9.3-p327/bundler/gems/jenkins_api_client-98d8f27bc0aa/lib/jenkins_api_client/job.rb:919:in `block in get_build_id_the_old_way'

introduced in 94bd8b1 (merged pull request arangamani#106)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants