Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonathanhle/9f38a671d72dd9fdac745ddce1211567 to your computer and use it in GitHub Desktop.
Save jonathanhle/9f38a671d72dd9fdac745ddce1211567 to your computer and use it in GitHub Desktop.
tfh-helper cancel pending and current runs
# Cancel Pending Runs
export project_env="nonprod"
export project_prefix="project-prefix-yada-foo-bar"
export working_workspaces=$(tfh workspace list | grep ${project_prefix} | grep ${project_env})
for wrkspace in ${working_workspaces}:
do
echo $wrkspace
pending_run=`tfh run list -name ${wrkspace} | grep "pending" | awk '{print $1}' | head -n 1`
if (echo ${pending_run} | wc -c) > 0
then
echo "Cancelling runs for $wrkspace. Run ${pending_run}"
tfh run cancel ${pending_run} -name $wrkspace
fi
done
# Discard Current Run
for wrkspace in ${working_workspaces}:
do
echo $wrkspace
latest_run=`tfh run list -name ${wrkspace} | grep -v "canceled" | grep "run-" | awk '{print $1}' | head -n 1`
if (echo ${latest_run} | wc -c) > 0
then
echo "Cancelling runs for $wrkspace. Run ${latest_run}"
tfh run discard ${latest_run} -name $wrkspace
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment