Last active
October 1, 2018 20:11
-
-
Save Hodglim/9ae56a7c6b77c056cf2f6d8f4fe87fc5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# AWS CodePipeline execution status | |
# | |
# by Darren Hodges (http://github.com/hodglim) | |
# | |
# <bitbar.title>AWS CodePipeline execution status</bitbar.title> | |
# <bitbar.version>v1.0</bitbar.version> | |
# <bitbar.author>Darren Hodges</bitbar.author> | |
# <bitbar.author.github>hodglim</bitbar.author.github> | |
# <bitbar.desc>Shows the status of the latest execution on each pipeline.</bitbar.desc> | |
# <bitbar.dependencies>awscli</bitbar.dependencies> | |
# | |
# Dependencies: | |
# awscli (https://aws.amazon.com/cli/) | |
export PATH="/usr/local/bin:/usr/bin:/bin:$PATH" | |
# Colours | |
DEFAULT_COLOUR="#000000" | |
SUCCESS_COLOUR="#29cc00" | |
INPROGRESS_COLOUR="#ff9933" | |
FAILED_COLOUR="#ff0033" | |
titleColour=$DEFAULT_COLOUR | |
# Fetch list of pipelines | |
pipelines=$(aws codepipeline list-pipelines --query='pipelines[*].name' --output=text) | |
# Get the latest execution for each pipeline | |
for pipeline in $pipelines; do | |
colour="#ff0033" | |
execution=$(aws codepipeline list-pipeline-executions --pipeline-name=$pipeline --max-results=1 --query='pipelineExecutionSummaries[*].{status:status,lastUpdateTime:lastUpdateTime}' --output=text) | |
lastUpdateTimestamp=$(echo $execution | cut -f1 -d$' ' | xargs printf "%.0f") | |
lastUpdateTime=$(echo $lastUpdateTimestamp | xargs date -r) | |
status=$(echo $execution | cut -f2 -d$' ') | |
if [ "$status" == "Succeeded" ]; then | |
colour=$SUCCESS_COLOUR | |
elif [ "$status" == "InProgress" ]; then | |
colour=$INPROGRESS_COLOUR | |
if [ "$titleColour" == $DEFAULT_COLOUR ]; then | |
titleColour=$INPROGRESS_COLOUR | |
fi | |
elif [ "$status" == "Failed" ]; then | |
colour=$FAILED_COLOUR | |
if [ "$titleColour" == $DEFAULT_COLOUR ] || [ "$titleColour" == $INPROGRESS_COLOUR ]; then | |
titleColour=$FAILED_COLOUR | |
fi | |
fi | |
output[$lastUpdateTimestamp]="$pipeline: $status | color=$colour href=https://eu-west-1.console.aws.amazon.com/codepipeline/home?region=eu-west-1#/view/$pipeline;Last update: $lastUpdateTime;" | |
done | |
# Sort latest pipeline executions to the top | |
sortedOutput=$(for k in "${!output[@]}"; do | |
echo $k';'${output["$k"]} | |
done | sort -rn -k3) | |
# Display output | |
echo "Pipeline | color=$titleColour" | |
echo "---" | |
IFS=$';' | |
count=0 | |
for out in $sortedOutput; do | |
count=`expr $count + 1` | |
# Don't display timestamps in the output | |
if [ ${#out} -ge 12 ]; then | |
echo $out | |
fi | |
# Display a divider between pipelines | |
if ! (($count % 3)); then | |
echo "---" | |
fi | |
done | |
unset IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment