Azure DevOps pipeline: alias not expanded in tcb-env-setup.sh

I’ve already opened a github issue but I prefer adding the info also here.

The script tcb-env-setup.sh that I download with
wget https://raw.githubusercontent.com/toradex/tcb-env-setup/master/tcb-env-setup.sh
defines an alias torizoncore-builder in the following way

alias torizoncore-builder='docker run --rm '"$interactive_flags"' '"$volumes"'-v "$(pwd)":/workdir -v '"$storage"':/storage -v /var/run/docker.sock:/var/run/docker.sock'"$network"'$(tcb_dynamic_params) '"$*"' torizon/torizoncore-builder:'"$chosen_tag"

The problem is that if I call this bash file from an Azure DevOps pipeline, the shell is not interactive and so aliases are not expanded.

The following lines must be added at the beginning of the script (after the first line)

# we need this to expand the aliases even in case of not interactive shell (CI/CD)
shopt -s expand_aliases

Otherwise, shopt -s expand_aliases must be called by the pipeline before sourcing.

If this is the expected way, please add this info to the documentation, please. If it’s already added and I missed it, sorry.

Hi, I’m the Toradex AI Assistant.

I might make mistakes or occasionally get you wrong. Our support team will step in if needed.


Thank you for bringing up this issue with the tcb-env-setup.sh script and CI/CD environments. Your analysis is correct — aliases are not expanded in non-interactive shells by default, which causes problems in CI/CD pipelines like Azure DevOps.

The Issue

The tcb-env-setup.sh script defines the torizoncore-builder alias as shown in your example(1). In non-interactive environments, this alias won’t be expanded without explicitly enabling alias expansion.

Solutions for CI/CD Environments

There are several approaches to resolve this:

Option 1: Enable Alias Expansion in Your Script

As you mentioned, adding these lines at the beginning of your script (after sourcing tcb-env-setup.sh):

# Enable alias expansion for non-interactive shells (CI/CD)
shopt -s expand_aliases
source tcb-env-setup.sh
torizoncore-builder build

(2)

Option 2: Define the Alias Manually

Some users in CI/CD environments manually define the alias command, as shown in TorizonCore Builder’s own testing pipeline(2). This approach gives you more control over the Docker command parameters.

Option 3: Use the script Command

Another workaround is to use the script command to simulate a TTY environment:

script -q -c "torizoncore-builder build"

(2)

Community Discussion

This issue has been discussed in the community, where users have encountered similar problems with TTY-related errors in GitHub Actions and other CI/CD environments(2). The community has provided various workarounds, including using sed to modify the setup script or manually defining the Docker command.

Recommendation

Your suggestion to add shopt -s expand_aliases to the setup script or document this requirement is valid. For now, the most reliable approach is to include the shopt -s expand_aliases command in your pipeline script before sourcing the setup script.

Best regards,
Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

Hi @vix!

We’ll discuss internally how to handle the use of TCB in pipelines.

For now, there is a possible workaround. In the TCB repo, you can check the functions.sh file, which defines the TCB through a Bash function, without these aliases. This allows you to bypass the issue and use TCB directly in your pipeline.

Best regards.

Hi @lucas_az.tx

if this is the supported scenario, it’s not a problem enabling alias expansion in the pipeline

shopt -s expand_aliases
source tcb-env-setup.sh
torizoncore-builder build

I suggest to add this info to the doc

Hi @vix!

Thanks for the suggestion!

We’ll discuss it with the Torizon team.

Best regards.