The following example shows
setting env_var_name Parameter dyncamically:
parameters:
tag-or-branch:
type: env_var_name
default: TAGANCH
- run:
name: Tag or Branch
command: |
if [[ -z "<< pipeline.git.branch >>" ]]; then
echo "export TAGANCH=<< pipeline.git.tag >>" >> $BASH_ENV
else echo "export TAGANCH=<< pipeline.git.branch >>" >> $BASH_ENV
fi
However when using the parameter, it will always contain the default value:
- run:
name: Tag or Branch Debug
command: echo "tag-or-branch ${<< parameters.tag-or-branch >>}"
will print
#!/bin/bash -eo pipefail
echo "tag_or_branch ${TAGANCH}"
tag_or_branch
CircleCI received exit code 0
even inside the same run statement it won’ work:
- run:
name: Tag or Branch
command: |
if [[ -z "<< pipeline.git.tag >>" ]]; then
echo "export TAGANCH=<< pipeline.git.tag >>" >> $BASH_ENV
else echo "export TAGANCH=<< pipeline.git.branch >>" >> $BASH_ENV
fi
echo "tag_or_branch ${<< parameters.tag_or_branch >>}"
echo "tag_or_branch $<< parameters.tag_or_branch >>"
echo "tag_or_branch ${TAGANCH}"
echo "tag_or_branch $TAGANCH"