Skip to content

Instantly share code, notes, and snippets.

@dustinmm80
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinmm80/0c9880f637828ef72eb6 to your computer and use it in GitHub Desktop.
Save dustinmm80/0c9880f637828ef72eb6 to your computer and use it in GitHub Desktop.
Extending Conjur::Command for custom plugins
require 'net/http'
require 'net/https'
require 'uri'
class Conjur::Command::Jenkins < Conjur::Command
desc 'Interact with Jenkins using Conjur credentials'
command :jenkins do |jenkins|
jenkins.desc 'Build a Jenkins job'
jenkins.arg_name 'job_name'
jenkins.command 'build' do |c|
c.action do |_, _, args|
job_name = require_arg(args, 'job_name')
uri = URI.parse("https://jenkins.myorg.com/job/#{job_name}/build")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.path)
req.basic_auth 'jenkins', api.variable('jenkins/api-token').value
resp = https.request(req)
puts "#{resp.code} #{resp.message}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment