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

Job#get_build_id_from_queue broken with newer Jenkins #277

Open
rmoriz opened this issue Mar 9, 2018 · 1 comment
Open

Job#get_build_id_from_queue broken with newer Jenkins #277

rmoriz opened this issue Mar 9, 2018 · 1 comment

Comments

@rmoriz
Copy link

rmoriz commented Mar 9, 2018

Scenario

Jenkins Version: 2.89.3

Problem

Queue API is called which is gone. Probably related: https://issues.jenkins-ci.org/browse/JENKINS-22865

Error

D, [2018-03-09T21:16:49.305280 #22278] DEBUG -- : GET /api/json?tree=useCrumbs
D, [2018-03-09T21:16:49.823369 #22278] DEBUG -- : HTTP Code: 200, Response Body: {"_class":"hudson.model.Hudson","useCrumbs":false}
D, [2018-03-09T21:16:49.823435 #22278] DEBUG -- : POST /job/test-project/build
D, [2018-03-09T21:16:50.359289 #22278] DEBUG -- : HTTP Code: 201, Response Body: 
D, [2018-03-09T21:16:50.359325 #22278] DEBUG -- : GET /
I, [2018-03-09T21:16:51.077691 #22278]  INFO -- : Job queued for test-project, will wait up to 10 seconds for build to start...
I, [2018-03-09T21:16:51.077763 #22278]  INFO -- : Obtaining the details of task with ID '1942'
D, [2018-03-09T21:16:51.077837 #22278] DEBUG -- : GET /queue/item/1942/api/json
D, [2018-03-09T21:16:51.605381 #22278] DEBUG -- : HTTP Code: 404, Response Body: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /queue/item/1942/api/json. Reason:
<pre>    Not Found</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>

</body>
</html>

E, [2018-03-09T21:16:51.605431 #22278] ERROR -- : JenkinsApi::Exceptions::NotFound: Requested component is not found on the Jenkins CI server.
build_number: 
W, [2018-03-09T21:16:51.605511 #22278]  WARN -- : Problem while waiting for 'test-project' build to start.  JenkinsApi::Exceptions::NotFound Requested component is not found on the Jenkins CI server.
Traceback (most recent call last):
	11: from test.rb:21:in `<main>'
	10: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/gems/2.5.0/gems/jenkins_api_client-1.5.3/lib/jenkins_api_client/job.rb:865:in `build'
	 9: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/gems/2.5.0/gems/jenkins_api_client-1.5.3/lib/jenkins_api_client/job.rb:899:in `get_build_id_from_queue'
	 8: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/2.5.0/timeout.rb:108:in `timeout'
	 7: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/2.5.0/timeout.rb:33:in `catch'
	 6: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/2.5.0/timeout.rb:33:in `catch'
	 5: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/2.5.0/timeout.rb:33:in `block in catch'
	 4: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'
	 3: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/gems/2.5.0/gems/jenkins_api_client-1.5.3/lib/jenkins_api_client/job.rb:906:in `block in get_build_id_from_queue'
	 2: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/gems/2.5.0/gems/jenkins_api_client-1.5.3/lib/jenkins_api_client/build_queue.rb:110:in `get_item_by_id'
	 1: from /Users/rmoriz/.asdf/installs/ruby/2.5.0/lib/ruby/gems/2.5.0/gems/jenkins_api_client-1.5.3/lib/jenkins_api_client/client.rb:377:in `api_get_request'

Example

require 'jenkins_api_client'

jenkins_client = JenkinsApi::Client.new(
  server_url: 'https://jenkins.example.com',
  username: 'user',
  password: 'pass',
  log_level: 0,
  ssl: true
)

opts = {
  'build_start_timeout' => 10,
  'completion_proc' => lambda do |build_number, _|
    puts "build_number: #{build_number}"
  end
}

jenkins_client.job.build("test-project", "", opts)

Workaround Hack

...
JenkinsApi::Client::Job.send(:remove_const, 'JENKINS_QUEUE_ID_SUPPORT_VERSION')
JenkinsApi::Client::Job::JENKINS_QUEUE_ID_SUPPORT_VERSION = '99.9'
jenkins_client.job.build("test-project", "", opts)
@QZ1220
Copy link

QZ1220 commented Oct 30, 2020

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

No branches or pull requests

2 participants