Skip to content

Instantly share code, notes, and snippets.

@carlovsk
Created September 19, 2025 15:46
Show Gist options
  • Select an option

  • Save carlovsk/38663c8c6f47756c9eb96b52eddf023f to your computer and use it in GitHub Desktop.

Select an option

Save carlovsk/38663c8c6f47756c9eb96b52eddf023f to your computer and use it in GitHub Desktop.
AWS Codebuild run
function aws-codebuild-start() {
# Check if fzf is available
if command -v fzf >/dev/null 2>&1; then
# Use fzf for project selection
local project=$(aws codebuild list-projects --query 'projects[]' --output table | tail -n +4 | head -n -2 | awk '{print $2}' | fzf --prompt="Select CodeBuild project: ")
else
# Fallback to manual selection
local projects=($(aws codebuild list-projects --query 'projects[]' --output text))
if [[ ${#projects[@]} -eq 0 ]]; then
echo "No CodeBuild projects found."
return 1
fi
echo "Select a project:"
for i in {1..${#projects[@]}}; do
echo "$i) ${projects[$i]}"
done
read "choice?Enter number (1-${#projects[@]}): "
if [[ ! "$choice" =~ ^[0-9]+$ ]] || [[ $choice -lt 1 ]] || [[ $choice -gt ${#projects[@]} ]]; then
echo "Invalid selection."
return 1
fi
local project=${projects[$choice]}
fi
# Check if project was selected
if [[ -z "$project" ]]; then
echo "No project selected."
return 1
fi
local project_account_id=$(aws sts get-caller-identity --query Account --output text)
echo "Starting build for project: $project"
# Start the build
local build_id=$(aws codebuild start-build --project-name "$project" --query 'build.id' --output text)
if [[ $? -ne 0 ]]; then
echo "Failed to start build."
return 1
fi
echo "✅ Build started: $build_id"
# Get latest build duration for time estimate
local latest_build_id=$(aws codebuild list-builds-for-project --project-name "$project" --query 'ids[0]' --output text 2>/dev/null)
if [[ -n "$latest_build_id" && "$latest_build_id" != "None" ]]; then
local latest_duration=$(aws codebuild batch-get-builds --ids "$latest_build_id" --query 'builds[0].phases[?phaseType==`COMPLETED`].durationInSeconds' --output text 2>/dev/null | head -1)
if [[ -n "$latest_duration" && "$latest_duration" != "None" && "$latest_duration" =~ ^[0-9]+$ ]]; then
local expected_time=$(date -d "+${latest_duration} seconds" "+%H:%M:%S" 2>/dev/null)
if [[ $? -eq 0 ]]; then
echo "⏱️ Expected completion time: $expected_time (based on ${latest_duration}s from latest build)"
else
echo "⏱️ Expected duration: ${latest_duration} seconds (from latest build)"
fi
else
echo "⏱️ Expected completion time: Unknown (no duration data from previous builds)"
fi
else
echo "⏱️ Expected completion time: Unknown (no previous builds found)"
fi
echo "🔗 Monitor at: https://console.aws.amazon.com/codesuite/codebuild/$project_account_id/$project/build/$project%3A${build_id##*:}/"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment