From fb5c1a96f6a1bb2b28b30eb9aa5639981b53fdb3 Mon Sep 17 00:00:00 2001 From: Florian Motlik Date: Thu, 14 Dec 2023 14:48:23 +0100 Subject: [PATCH 1/2] Add option to limit number of codebuild builds, set to 10 by default --- scripts/commands/codebuild/builds.bash | 12 +++++++++++- scripts/commands/codebuild/builds.md | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/commands/codebuild/builds.bash b/scripts/commands/codebuild/builds.bash index fc1a6cd..60e4ded 100644 --- a/scripts/commands/codebuild/builds.bash +++ b/scripts/commands/codebuild/builds.bash @@ -1,10 +1,20 @@ +MAX_BUILDS="10" + +while getopts "m:" opt; do + case "$opt" in + m) MAX_BUILDS="$OPTARG" ;; + esac +done + +shift "$(($OPTIND - 1))" + split_args "$@" PROJECTS=$(awscli codebuild list-projects --output text --query "projects[$(auto_filter_joined @ -- "$FIRST_RESOURCE")].[@]") select_one Project "$PROJECTS" -BUILD_IDS=$(awscli codebuild list-builds-for-project --max-items 99 --project-name "$SELECTED" --output text --query "ids[].[@]" | head -n 99 ) +BUILD_IDS=$(awscli codebuild list-builds-for-project --max-items "$MAX_BUILDS" --project-name "$SELECTED" --output text --query "ids[].[@]" | sed '$d' ) awscli codebuild batch-get-builds --output table --query "reverse(builds)[$(auto_filter_joined id buildNumber currentPhase buildStatus -- "$SECOND_RESOURCE")].{ \"1.Id\":id, diff --git a/scripts/commands/codebuild/builds.md b/scripts/commands/codebuild/builds.md index 588c450..f11a4c7 100644 --- a/scripts/commands/codebuild/builds.md +++ b/scripts/commands/codebuild/builds.md @@ -2,6 +2,10 @@ List all builds for a project +## Options + +* `-m`: Number of builds to show + ## Filter matches against * Project Name From 4c1364ac8273a5c7b2930826daecfe02a85b1591 Mon Sep 17 00:00:00 2001 From: Florian Motlik Date: Thu, 14 Dec 2023 17:53:32 +0100 Subject: [PATCH 2/2] Add Build Status Command --- docs/_index.md | 1 + scripts/commands/codebuild/build-status.bash | 10 ++++++++++ scripts/commands/codebuild/build-status.md | 11 +++++++++++ scripts/commands/codebuild/build_selection.sh | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 scripts/commands/codebuild/build-status.bash create mode 100644 scripts/commands/codebuild/build-status.md diff --git a/docs/_index.md b/docs/_index.md index b4f92c6..9f5878a 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -168,6 +168,7 @@ Following is a list of all available commands and links to their source document * [`codebuild`](https://github.com/theserverlessway/awsinfo/blob/master/scripts/commands/codebuild/index.md) * [`codebuild build`](https://github.com/theserverlessway/awsinfo/blob/master/scripts/commands/codebuild/build.md) * [`codebuild build-reports`](https://github.com/theserverlessway/awsinfo/blob/master/scripts/commands/codebuild/build-reports.md) +* [`codebuild build-status`](https://github.com/theserverlessway/awsinfo/blob/master/scripts/commands/codebuild/build-status.md) * [`codebuild builds`](https://github.com/theserverlessway/awsinfo/blob/master/scripts/commands/codebuild/builds.md) * [`codebuild report`](https://github.com/theserverlessway/awsinfo/blob/master/scripts/commands/codebuild/report.md) * [`codebuild report-groups`](https://github.com/theserverlessway/awsinfo/blob/master/scripts/commands/codebuild/report-groups.md) diff --git a/scripts/commands/codebuild/build-status.bash b/scripts/commands/codebuild/build-status.bash new file mode 100644 index 0000000..0b925cb --- /dev/null +++ b/scripts/commands/codebuild/build-status.bash @@ -0,0 +1,10 @@ +source $CURRENT_COMMAND_DIR/build_selection.sh + +awscli codebuild batch-get-builds --output table --ids $SELECTED --query "builds[].{ + \"1.Id\":id, + \"2.Number\":buildNumber, + \"3.Phase\":currentPhase, + \"4.Status\":buildStatus, + \"5.StartedAt\":startTime, + \"6.FinishedAt\":endTime, + \"7.Environment\":environment}" \ No newline at end of file diff --git a/scripts/commands/codebuild/build-status.md b/scripts/commands/codebuild/build-status.md new file mode 100644 index 0000000..e450f09 --- /dev/null +++ b/scripts/commands/codebuild/build-status.md @@ -0,0 +1,11 @@ +# `awsinfo codebuild build-status [first-filters]+ -- [second-filters]*` + +Show only the status and most relevant data of a build + +## First Filter matches against + +* Project Name + +## Second Filter matches against + +* Build Id diff --git a/scripts/commands/codebuild/build_selection.sh b/scripts/commands/codebuild/build_selection.sh index c7cc68b..763922d 100644 --- a/scripts/commands/codebuild/build_selection.sh +++ b/scripts/commands/codebuild/build_selection.sh @@ -6,4 +6,4 @@ select_one Project "$PROJECTS" BUILD_IDS=$(awscli codebuild list-builds-for-project --project-name "$SELECTED" --max-items 100 --output text --query "ids[$(auto_filter_joined @ -- "$SECOND_RESOURCE")].[@]") -select_one Build "$BUILD_IDS" \ No newline at end of file +select_one_unsorted Build "$BUILD_IDS" \ No newline at end of file