scripts
which can be executed via the sdf exec
command. In this way, you may string multiple commmands together, sequentially.
scripts
is a reserved name keyword in the config
yml block. Each property in scripts will be an independently executable command.
To execute any script run: sdf exec [SCRIPT_NAME]
Keep in mind:
- If a subcommand exits with an error code, SDF will propagate that error code, and exit with that same error code
- SDF pipes both
stdout
andstderr
from subcommands - Scripts are run via the
sh
shell. Color coding will not be preserved.
Getting Started
To configure a custom script, add ascripts
element to the config
block. Each element in the properties
array will become a separately executable command.
sdf exec my_script
sdf exec other_script
sdf exec macro_script
Reserved Script Keywords: Pre-Compile, Pre-Run, Post-Compile & Post-Run
In addition to generic scripts, SDF has 4 reserved keywords which will execute scripts natively as part ofsdf compile
and sdf run
commands.
pre-compile
-> When executingsdf compile
orsdf check
orsdf report
, the script in pre-compile is executed firstpost-compile
-> When executingsdf compile
orsdf check
orsdf report
, the script in post-compile is executed after compile has successfully finishedpre-run
-> When executingsdf run
orsdf test
orsdf stats
, the script in pre-run is executed firstpost-run
-> When executingsdf run
orsdf test
orsdf stats
, the script in post-run is executed after run has successfully finished
Example
The configuration below utilizes all 4 keywords. Let’s add it to the default workspace fromsdf new
sdf compile
, we now run the pre-compile script first, and then post-compile resulting in the below output.
Use Cases
Scripts allow for organization specific workflows- Pre-hooks and Post-hooks -> Run custom logic before or after an SDF command
- Metadata uploading -> Upload SDF’s information schema to a database for further processing.
- Post processing -> Parse metadata for post-run statistics
- Validate results -> Run python, js, shell, or any other process to validate that current changes fit with your current data infrastructure.
User & Root User
Scripts inherit the user of the calling SDF process. As a resultsudo sdf exec ...
will run subcommands as sudo as well.
See the below script to validate whether an SDF script is root.