I'd like to make a toggle parameter in my Azure Pipelines CI template, which would switch between 1) using built-in Gradle distribution and 2) using Gradle distribution from wrapper.
Without such a single toggle, if I want to use a wrapper distribution, I'll need to replace gradle
command invocations with ./gradlew
-script invocation in all script:
steps.
My idea is to conditionally create the following alias for Bash: alias gradle='./gradlew'
before main pipeline steps begin.
My question is: how to create Bash alias for Azure Pipelines, which will become implicitly available for all further script:
steps?
Based on the Azure Pipelines logs output, I can see that Bash script:
steps get invoked as: /usr/bin/bash --noprofile --norc /home/vsts/work/_temp/your_actual_script_content.sh
So, I guess --noprofile --norc
means that .profile
and .bashrc
files will be ignored.
What I've tried instead is setting BASH_ENV=~/my_ci_env.sh
for the whole Pipelines stage, where my_ci_env.sh
contains alias configuration. Unfortunately, this didn't work out. What are the other approaches which might work in my situation? I'm pretty sure creating such alias should be possible, because at least values from Azure Pipelines variables:
somehow become available in Bash script:
steps as environment variables.
The function approach injected with BASH_ENV
worked out well. Here is the solution:
steps:
- ${{ if eq(parameters.useGradleWrapper, true) }}:
- script: |
cat >> ~/ci_bash_env.sh <<END
gradle() {
./gradlew "\$@"
}
export -f gradle
END
echo "##vso[task.setvariable variable=BASH_ENV]~/ci_bash_env.sh"
As Barmar said in comments, aliases don't seem to work in such situation (non-interactive shell), that's why my initial solution has failed.