I have found a really terribly annoying feature of Azure DevOps that I was not aware of, maybe it just never caused any problems in the past for me.
When I run a script using a Bash@3 task, even though I'm stating the script path, for some reason AZDO runs the script from the context of some temp folder wo which it copies the script file. Because I also use my script for local compilation and want to be able to call it from anywhere, for sourcing some other file in the same folder as the script I use the scripts actual location. But since the location now seems to be this temp folder, my other file is not there and the script fails.
This is what I do in my pipeline yml:
- task: Bash@3
displayName: Build something
enabled: true
continueOnError: false
inputs:
failOnStderr: true
filePath: 'CI/build_something.sh'
arguments: y
# I tried it with and without stating the working directory, doesn't make a difference
#workingDirectory: CI
This is what I try to do in my build script:
echo "pwd:"
pwd
script_dir=`dirname $0`
echo "script_dir: ${script_dir}"
# this is the trouble maker that breaks the script
source `dirname $0`/build_vars.list
And this is what I get back from AZDO when running the pipeline task:
pwd:
/opt/agent/build/_work/1/s/CI
script_dir: /opt/agent/build/_work/_temp
/opt/agent/build/_work/1/s/CI/build_something.sh: line 9: /opt/agent/build/_work/_temp/build_vars.list: No such file or directory
I was always under the impression, that only inline scripts are copied as .sh files to a temporary folder, but this is not an inline script. Is there a way to suppress this behavior? I have a hard time wrapping my head around this. Why is it done this way?
Does anybody have an elegant solution for getting around this?
PS: I should mention I'm working on a somewhat old version of AZDO from 2019