From 2a505c55201316a704739abad718ad8feccc0acd Mon Sep 17 00:00:00 2001 From: Tony Chia Date: Sat, 21 Jan 2017 20:33:29 -0800 Subject: [PATCH 1/2] added get-codebuild-build-log to help with debugging failing codebuild build --- alias | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/alias b/alias index fc01acd..51f583f 100644 --- a/alias +++ b/alias @@ -134,3 +134,23 @@ revoke-my-ip-all = !f() { aws revoke-my-ip ${1} all all }; f + +get-codebuild-build-log = + !f() { + if [ "${1}" == "" ]; then + echo "Please enter the codebuild project name" + exit 1 + else + log_group_name="/aws/codebuild/${1}" + fi + if [ "${2}" == "" ]; then + echo "Please enter the codebuild build id" + exit 1 + else + log_stream_name="${2}" + fi + aws logs get-log-events \ + --log-group-name ${log_group_name} \ + --log-stream-name ${log_stream_name} \ + --output text | cut -f3- | sed '/^$/d' | less + }; f From d19262be1a60b043d073d201c4ab254251e8762b Mon Sep 17 00:00:00 2001 From: Tony Chia Date: Sun, 22 Jan 2017 00:08:13 -0800 Subject: [PATCH 2/2] Made the 2nd parameter(build id) optional. If it's empty it will use the latest id --- alias | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/alias b/alias index 51f583f..86fe397 100644 --- a/alias +++ b/alias @@ -135,7 +135,20 @@ revoke-my-ip-all = aws revoke-my-ip ${1} all all }; f -get-codebuild-build-log = +codebuild-get-latest-id = + !f() { + if [ "${1}" == "" ]; then + echo "Please enter the codebuild project name" + exit 1 + else + project_name="${1}" + fi + aws codebuild list-builds-for-project \ + --project-name ${project_name} --query 'ids[0]' --output text |cut -d: -f2 + }; f + + +codebuild-tail-log = !f() { if [ "${1}" == "" ]; then echo "Please enter the codebuild project name" @@ -144,13 +157,14 @@ get-codebuild-build-log = log_group_name="/aws/codebuild/${1}" fi if [ "${2}" == "" ]; then - echo "Please enter the codebuild build id" - exit 1 + echo "Getting the latest build id for codebuild project name ${1}" + log_stream_name=$(aws codebuild-get-latest-id ${1}) + echo "latest build id/log stream name=${log_stream_name}" else log_stream_name="${2}" fi aws logs get-log-events \ --log-group-name ${log_group_name} \ --log-stream-name ${log_stream_name} \ - --output text | cut -f3- | sed '/^$/d' | less + --output text | cut -f3- | sed '/^$/d' }; f