Skip to content
Snippets Groups Projects
Unverified Commit 05a987a8 authored by Timo Furrer's avatar Timo Furrer
Browse files

Support env variable to force sourcing `gitlab-tofu`

Changelog: added
parent 8d8c0d7d
Branches
Tags
No related merge requests found
...@@ -280,6 +280,26 @@ plan: ...@@ -280,6 +280,26 @@ plan:
- apk add jq - apk add jq
``` ```
### Source `gitlab-tofu` script to run custom commands later
The `gitlab-tofu` script can be sourced instead of executed.
This allows you to setup the shell and run your own `tofu` or
`gitlab-tofu` commands.
You can use the following snipped either in your script,
directly in the shell and also in `script` keywords of your
pipeline job:
```shell
. $(which gitlab-tofu)
```
There is a slight chance when doing this in a more exotic environment
or shell that `gitlab-tofu` is not able to detect that it is sourced
and will try to execute a `tofu` command.
In this case you can set the `GITLAB_TOFU_SOURCE` environment variable
to `true` before sourcing `gitlab-tofu`.
### Best Practices ### Best Practices
This section is a collection of *some* best practices. This section is a collection of *some* best practices.
......
...@@ -295,6 +295,26 @@ plan: ...@@ -295,6 +295,26 @@ plan:
- apk add jq - apk add jq
``` ```
### Source `gitlab-tofu` script to run custom commands later
The `gitlab-tofu` script can be sourced instead of executed.
This allows you to setup the shell and run your own `tofu` or
`gitlab-tofu` commands.
You can use the following snipped either in your script,
directly in the shell and also in `script` keywords of your
pipeline job:
```shell
. $(which gitlab-tofu)
```
There is a slight chance when doing this in a more exotic environment
or shell that `gitlab-tofu` is not able to detect that it is sourced
and will try to execute a `tofu` command.
In this case you can set the `GITLAB_TOFU_SOURCE` environment variable
to `true` before sourcing `gitlab-tofu`.
### Best Practices ### Best Practices
This section is a collection of *some* best practices. This section is a collection of *some* best practices.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# set some shell options # set some shell options
set -o errexit set -o errexit
if [ "${DEBUG_OUTPUT}" = "true" ]; then if [ "${DEBUG_OUTPUT}" = "true" ]; then
set -o xtrace set -o xtrace
fi fi
...@@ -24,7 +24,9 @@ fi ...@@ -24,7 +24,9 @@ fi
# Evaluate if this script is being sourced or executed directly. # Evaluate if this script is being sourced or executed directly.
# See https://stackoverflow.com/a/28776166 # See https://stackoverflow.com/a/28776166
sourced=0 sourced=0
if [ -n "$ZSH_VERSION" ]; then if [ "$GITLAB_TOFU_SOURCE" = 'true' ]; then
sourced=1
elif [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$KSH_VERSION" ]; then elif [ -n "$KSH_VERSION" ]; then
# shellcheck disable=SC2296 # shellcheck disable=SC2296
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment