From a54e35446a932f5a2a63cf420fefeb0f90d91b1b Mon Sep 17 00:00:00 2001 From: ispasov Date: Fri, 4 Jul 2025 19:20:14 +0300 Subject: [PATCH] [GitLab CI] Improve env var setting Allow env vars to either be set with or without CUSTOM_ENV_ prefix. The prefix is added automatically by GitLab if the var is set from the UI. If the variable is set from the container, it is not prefixed. Both approaches are valid so support both. --- GitLab/custom-executor.md | 14 +++++++------- GitLab/scripts/base.sh | 10 +++++----- GitLab/scripts/prepare.sh | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/GitLab/custom-executor.md b/GitLab/custom-executor.md index 90d4549..8b957f6 100644 --- a/GitLab/custom-executor.md +++ b/GitLab/custom-executor.md @@ -59,13 +59,13 @@ To do that: The provided scripts expect the following environment variables to be set: -- `CUSTOM_ENV_ORKA_TOKEN` - User authentication to connect to the Orka environment. Created by running `orka3 user get-token` or `orka3 serviceaccount token `. -- `CUSTOM_ENV_ORKA_ENDPOINT` - The Orka endpoint. Usually, it is `http://10.221.188.20`. -- `CUSTOM_ENV_ORKA_CONFIG_NAME` - The name of the VM config to be deployed. -- `CUSTOM_ENV_ORKA_VM_NAME_PREFIX` - The prefix of the generated VM name. Defaults to `gl-runner`. -- `CUSTOM_ENV_ORKA_VM_USER` - User used to SSH to the VM. -- `CUSTOM_ENV_ORKA_SSH_KEY_FILE` - The private SSH key contents to use when connecting to the VM. This key was created earlier during the Orka base image setup. -- `CUSTOM_ENV_VM_DEPLOYMENT_ATTEMPTS` - The number of attempts the executor tries to deploy a VM before it fails. Defaults to `1`. Note - GitLab automatically retries 3 times. This env var allows additional retry attempts. +- `ORKA_TOKEN` - User authentication to connect to the Orka environment. Created by running `orka3 user get-token` or `orka3 serviceaccount token `. +- `ORKA_ENDPOINT` - The Orka endpoint. Usually, it is `http://10.221.188.20`. +- `ORKA_CONFIG_NAME` - The name of the VM config to be deployed. +- `ORKA_VM_NAME_PREFIX` - The prefix of the generated VM name. Defaults to `gl-runner`. +- `ORKA_VM_USER` - User used to SSH to the VM. Defaults to `admin`. +- `ORKA_SSH_KEY_FILE` - The private SSH key contents to use when connecting to the VM. This key was created earlier during the Orka base image setup. +- `VM_DEPLOYMENT_ATTEMPTS` - The number of attempts the executor tries to deploy a VM before it fails. Defaults to `1`. Note - GitLab automatically retries 3 times. This env var allows additional retry attempts. For more information about GitLab CI/CD environment variables, see [here][env-variables]. diff --git a/GitLab/scripts/base.sh b/GitLab/scripts/base.sh index fcaa53f..72bffc6 100755 --- a/GitLab/scripts/base.sh +++ b/GitLab/scripts/base.sh @@ -3,11 +3,11 @@ BUILD_ID="runner-$CUSTOM_ENV_CI_RUNNER_ID-project-$CUSTOM_ENV_CI_PROJECT_ID-concurrent-$CUSTOM_ENV_CI_CONCURRENT_PROJECT_ID" export CONNECTION_INFO_ID=$BUILD_ID-connection-info -export ORKA_TOKEN=${CUSTOM_ENV_ORKA_TOKEN:-} -export ORKA_ENDPOINT=${CUSTOM_ENV_ORKA_ENDPOINT:-} -export ORKA_CONFIG_NAME=${CUSTOM_ENV_ORKA_CONFIG_NAME:-} -export ORKA_VM_NAME_PREFIX=${CUSTOM_ENV_ORKA_VM_NAME_PREFIX:-gl-runner} -export ORKA_VM_USER=${CUSTOM_ENV_ORKA_VM_USER:-admin} +export ORKA_TOKEN=${ORKA_TOKEN:-${CUSTOM_ENV_ORKA_TOKEN:-}} +export ORKA_ENDPOINT=${ORKA_ENDPOINT:-${CUSTOM_ENV_ORKA_ENDPOINT:-}} +export ORKA_CONFIG_NAME=${ORKA_CONFIG_NAME:-${CUSTOM_ENV_ORKA_CONFIG_NAME:-}} +export ORKA_VM_NAME_PREFIX=${ORKA_VM_NAME_PREFIX:-${CUSTOM_ENV_ORKA_VM_NAME_PREFIX:-gl-runner}} +export ORKA_VM_USER=${ORKA_VM_USER:-${CUSTOM_ENV_ORKA_VM_USER:-admin}} ORKA_SSH_KEY_FILE=${CUSTOM_ENV_ORKA_SSH_KEY_FILE:-} mkdir -p ~/.ssh diff --git a/GitLab/scripts/prepare.sh b/GitLab/scripts/prepare.sh index 8f43a91..0d757af 100755 --- a/GitLab/scripts/prepare.sh +++ b/GitLab/scripts/prepare.sh @@ -6,7 +6,7 @@ currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source "${currentDir}/base.sh" -VM_DEPLOYMENT_ATTEMPTS=${CUSTOM_ENV_VM_DEPLOYMENT_ATTEMPTS:-1} +VM_DEPLOYMENT_ATTEMPTS=${VM_DEPLOYMENT_ATTEMPTS:-${CUSTOM_ENV_VM_DEPLOYMENT_ATTEMPTS:-1}} function cleanup_on_failure { if [ -f "$BUILD_ID" ]; then