Skip to content

Executing Scripts

Simon B. Støvring edited this page Apr 23, 2024 · 1 revision

Tartelet can execute scripts during the lifecycle of a virtual machine. Scripts that are run during a virtual machine's lifecycle should be located in the ~/.tartelet folder on the virtual machine. This folder does not exist by default and must be manually created on the virtual machine.

Lifecycle Event File Path Description
Post-boot ~/.tartelet/post-boot.sh The script is executed after the virtual machine has booted.
Pre-run ~/.tartelet/pre-run.sh The script is executed before a job in a workflow runs.
Post-run ~/.tartelet/post-run.sh The script is executed after all the steps in a job have run.

Tartelet exposes some environment variables that are available to the scripts being run. Refer to the table below for the environment variables exposed by Tartelet and at which point in the lifecycle they are available.

Environment Variable Lifecycle Events Description
RUNNER_NAME Post-boot The name of the runner.

Recall that Tartelet destroys the virtual machine after a job has run, after which a new virtual machine is created and booted, and the lifecycle events are triggered again.

Follow the steps below to add a script to the virtual machine.

1. Stop the virtual machines

First, ensure that the virtual machines are not running by selecting Tartelet's menu bar item and then selecting "Stop".

Screenshot of the menu presented by selecting Tartelet's menu bar item with the Stop menu item highlighted.

2. Edit virtual machine

Select Tartelet's menu bar item again and then select "Edit Virtual Machine". This will open the virtual machine.

3. Create the ~/.tartelet folder

Open Finder or the Terminal to create a folder at ~/.tartelet if it does not already exist.

4. Add the script to the ~/.tartelet folder

Finally, add to the script. It is key that the scripts are named as Tartelet expects. Refer to the table at the top of this document for the correct filenames.

For the sake of this example, we will add the two following two scripts.

pre-run.sh

#!/bin/bash
echo "🚀 The job is about to start."

post-run.sh

#!/bin/bash
echo "🏁 The job has ended."
Screenshot of the folder containing the two scripts.

4. Test that it works

We can now start the virtual machines again and verify that our pre- and post-run scripts work by starting a GitHub Actions job. Notice that we can see the output of the scripts in the "Set up runner" and "Complete runner" phases in the workflow's log on github.com.

Screenshot of a workflow's run showing the messages echoed by our pre-run.sh and post-run.sh example scripts that were created earlier.