Last active
August 29, 2015 14:20
-
-
Save dustinmm80/0c9880f637828ef72eb6 to your computer and use it in GitHub Desktop.
Extending Conjur::Command for custom plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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