jenkins_api_client
jenkins_api_client copied to clipboard
compare_version does not work for all versions of jenkins
The compare_version
method does not work for all versions of jenkins.
> ver = client.get_jenkins_version
=> "1.625.3.1 (CloudBees Jenkins Enterprise 15.11)"
> client.compare_versions ver, '1.519'
NoMethodError: undefined method `[]' for nil:NilClass
from /Users/me/.rvm/gems/@default/gems/jenkins_api_client-1.4.5/lib/jenkins_api_client/client.rb:577:in `compare_versions'
> client.compare_versions '1.625.3.1', '1.519'
NoMethodError: undefined method `[]' for nil:NilClass
from /Users/me/.rvm/gems/@default/gems/jenkins_api_client-1.4.5/lib/jenkins_api_client/client.rb:577:in `compare_versions'
On such a jenkins server trying to start a jenkins job with a build_start_timeout
fails with that exception.
It looks like the Regexp used in the deconstruct_version_string
method is too strict. It expects the version to be exactly 3 groups of dot-separated numbers, not 4 or any trailing characters.
Dropping the trailing $
in the match
line below could fix the issue.
def deconstruct_version_string(version)
match = version.match(/^(\d+)\.(\d+)(?:\.(\d+))?$/)
# Match should have 4 parts [0] = input string, [1] = major
# [2] = minor, [3] = patch (possibly blank)
if match && match.size == 4
return [match[1].to_i, match[2].to_i, match[3].to_i || 0]
else
return nil
end
end
#282 resolves this issue.