-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example TTPs: Cleanup Feature (#435)
Summary: Pull Request resolved: #435 * Add new example TTPs for cleanup actions * Subsequent documentation will link to these example TTPs as code snippets * Also improved output formatting a bit Reviewed By: nicolagiacchetta Differential Revision: D51459133 fbshipit-source-id: 79b94cd7f5bb12d1516a8b438e30e49f5ee3d1c4
- Loading branch information
1 parent
24fe555
commit 331c819
Showing
5 changed files
with
66 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
name: Basic Cleanup Demonstration | ||
description: | | ||
Every time a step completes successfully, its cleanup action is enqueued. | ||
Then, the enqueued cleanup steps are run in reverse order | ||
("last in, first out") whenever: | ||
1. The TTP Completes Successfully, or... | ||
2. A Step Fails | ||
steps: | ||
- name: first_step | ||
print_str: | | ||
This step completes successfully, so its cleanup action will be enqueued. | ||
cleanup: | ||
print_str: "Cleaning up first_step" | ||
- name: second_step | ||
print_str: | | ||
This step has no cleanup action defined, so it will be skipped during cleanup | ||
- name: third_step | ||
print_str: | | ||
This step uses an `inline:` action instead of a `print_str:` action | ||
as its cleanup action - you may use any of TTPForge's supported action types | ||
as a cleanup action. | ||
cleanup: | ||
inline: echo "Cleaning up third_step" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
name: Default Cleanup Actions Demo | ||
description: | | ||
Certain types of actions, such as `create_file`, have a default cleanup | ||
action that you can enable by specifying `cleanup: default` in the relevant | ||
step. This TTP shows how the `create_file` default cleanup action deletes | ||
the created file. | ||
steps: | ||
- name: create_file_cleanup_demo | ||
create_file: /tmp/ttpforge-default-cleanup-demo-{{randAlphaNum 10}} | ||
contents: this will be automatically deleted... | ||
cleanup: default |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
name: Basic Cleanup Demonstration | ||
description: | | ||
If a step fails, we stop executing new steps, and begin | ||
cleaning up the prior steps in reverse order starting from the last | ||
successful step. | ||
steps: | ||
- name: first_step | ||
print_str: | | ||
This step completes successfully, so its cleanup action will be enqueued. | ||
cleanup: | ||
print_str: Cleaning up first_step | ||
- name: second_step | ||
print_str: So does this step. | ||
cleanup: | ||
print_str: Cleaning up second_step | ||
- name: third_step | ||
inline: | | ||
echo "This step fails, so it will not have its cleanup action run..." | ||
notarealcommandwillcauseafailure | ||
cleanup: | ||
print_str: This won't run! | ||
- name: fourth_step | ||
print_str: | | ||
Since the previous step failed, this step won't run at all... | ||
cleanup: | ||
print_str: ...and therefore its cleanup action won't run either. |
This file contains 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
This file contains 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