Skip to content

Instantly share code, notes, and snippets.

@alexandreprates
Last active May 4, 2016 18:51
Show Gist options
  • Select an option

  • Save alexandreprates/46fbc7d9454841fb5fdee8e014e98bbb to your computer and use it in GitHub Desktop.

Select an option

Save alexandreprates/46fbc7d9454841fb5fdee8e014e98bbb to your computer and use it in GitHub Desktop.
Start Jenkins build on command line
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'yaml'
def http_get(url)
url = URI.parse url
response = Net::HTTP.get_response(url)
case response.code
when '201', '302'
puts "Build in progress! ☕ "
else
puts "Ops, something whent wrong :("
end
end
BUILDLIST = File.join(ENV['HOME'], '.build.yml')
urls = YAML.load_file BUILDLIST
case ARGV
when ['list']
urls.each do |project, stages|
puts "#{project}\n #{stages.keys.join(', ')}\n\n"
end
exit 0
when ['edit']
system "vim #{BUILDLIST}"
end
unless ARGV[1] == 'in'
puts "usage: build [options]\nExamples:\n\tbuild project in stage"
exit(1)
end
project = ARGV[0]
stage = ARGV[2]
url = urls[project] && urls[project][stage]
if url
http_get(url)
else
warn "Can't know nothing about #{project} in #{stage}!"
end
curl https://gist.githubusercontent.com/alexandreprates/46fbc7d9454841fb5fdee8e014e98bbb/raw/3a05a2aa657b41196da688106c0742c1df98b570/build > /usr/bin/build && chmod +x /usr/bin/build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment