Created
July 22, 2019 23:01
-
-
Save jonathanhle/9f38a671d72dd9fdac745ddce1211567 to your computer and use it in GitHub Desktop.
tfh-helper cancel pending and current runs
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
| # 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