Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a build that is currently running/being executed?

Tags:

rest

build

bamboo

I am trying to stop Bamboo builds (that are currently running) if they pass a certain use case.

I have a list of the builds that I need to stop. Now, I want to send a REST request to stop the build(s) very similar to the "Stop Build" button that is on the top right of a build (see image). enter image description here

In the REST API documentation I have only seen this which only stops the build if it is queued.

https://docs.atlassian.com/bamboo/REST/3.3-SNAPSHOT/

/queue/{projectKey}-{buildKey}-{buildNumber}

Stop build execution, however only if build has not been started yet - so if is waiting in the build queue. If build does not exist in the queue anymore, method has no effect.

I need a way to stop RUNNING builds.

like image 894
Scott B Avatar asked Sep 06 '16 23:09

Scott B


1 Answers

I was able to figure out the names of the Bamboo builds I needed to stop via my own automation server. Then I was able to achieve this by hitting the stopPlan button code directly. Here is the Ruby method I wrote:

# Get request to stop a build located at the given url
def stop_bamboo_build_request(build_key)
  logger.debug "Build Key: #{build_key}"
  uri = URI("#{Rails.configuration.bamboo_base_url}/build/admin/stopPlan.action?planKey=#{build_key}")

  # Create client
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER

  # Create Request
  req =  Net::HTTP::Get.new(uri)
  # Add Auth
  req.basic_auth(Rails.configuration.bamboo_username, Rails.configuration.bamboo_password)

  # Add headers
  req.add_field "X-Atlassian-Token", "no-check"

  # Fetch Request
  res = http.request(req)
  logger.debug "Response HTTP Status Code: #{res.code}"
  logger.debug "Response HTTP Response Body: #{res.body}"
rescue StandardError => e
  logger.debug "HTTP Request failed (#{e.message})"
end
like image 80
Scott B Avatar answered Nov 15 '22 04:11

Scott B