Created
November 20, 2015 14:14
-
-
Save turhn/673fc181d91e37805691 to your computer and use it in GitHub Desktop.
AWS Get Last Deployment's Commit Id
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
#!/usr/bin/env ruby | |
require 'json' | |
class Deployments | |
def initialize(app_name, deployment_group) | |
@app_name, @deployment_group = app_name, deployment_group | |
end | |
def latest_successful_deployments | |
JSON.parse %x(aws deploy list-deployments \ | |
--deployment-group-name=#{@deployment_group} \ | |
--application-name=#{@app_name} \ | |
--include-only-statuses=Succeeded) | |
end | |
def latest_commit | |
latest_id = latest_successful_deployments["deployments"].first | |
latest_deployment = JSON.parse %x(aws deploy get-deployment --deployment-id=#{latest_id}) | |
latest_deployment["deploymentInfo"]["revision"]["gitHubLocation"]["commitId"] | |
end | |
end | |
unless ARGV.length == 2 | |
puts 'Usage: lcommitid <ApplicationName> <DeploymentGroup>' | |
else | |
d = Deployments.new ARGV[0], ARGV[1] | |
puts d.latest_commit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment