Shell / Bash
Create a Bash template#
- Go to Task Templates and click New Template.
- Select Bash as the app type.
- Configure it:
| Field | Description |
|---|---|
| Name | A descriptive name for the template |
| Repository | The repository containing your script |
| Playbook / Script | Relative path to the script, e.g. scripts/deploy.sh |
| Variable Groups | Variable groups whose values are injected as environment variables |
- Create, then Run.
Passing variables#
Values from the selected variable groups arrive as environment variables:
#!/bin/bash
set -euo pipefail
echo "Deploying to $TARGET_HOST"Secrets from the Secrets tab of a variable group arrive the same way, but are never written to the task log.
If the template is a build or deploy type, Semaphore also supplies the pipeline variables — SEMAPHORE_TASK_DETAILS_TYPE, SEMAPHORE_TASK_DETAILS_TARGET_VERSION, and the rest. See Pipelines.
Rules of the road#
- Make the script executable (
chmod +x) or give it a valid shebang (#!/bin/bash). - Scripts run non-interactively. Anything that waits for input hangs the task until it is stopped.
- Exit code
0means success. Any non-zero exit marks the task failed — soset -eis usually what you want, not a nicety. - To act on remote hosts, use Ansible rather than wrapping
sshin a script: you get inventory, credentials and per-host reporting for free.
Where it runs#
The script executes wherever the task executes — on the Semaphore server by default, or on the runner that picks the task up. Whatever the script calls (aws, kubectl, psql) has to be installed there.