'Azure Pipelines $Build.SourcesDirectory listing empty directory
I have azure debug pipeline that looks like below. I use $(Build.SourcesDirectory) azure variable to list content of my repository. Unfortunately, for some reason the content of SourcesDirectory is empty. Why? What am I doing wrong? I remember that it used to work.
pool:
vmImage: ubuntu-latest
stages:
- stage: Debug
displayName: Debug
jobs:
- deployment: Debug
displayName: Debug
strategy:
runOnce:
deploy:
steps:
- task: CmdLine@2
displayName: Debug
inputs:
script: |
echo 'Build.SourcesDirectory'
echo $(Build.SourcesDirectory)
ls -l $(Build.SourcesDirectory)
Solution 1:[1]
I still don't know the reason behind why it didn't work in first place (I guess some pipeline permissions or settings that I don't have/know) but, I found the fix that worked for me.
I had to add checkout: self step (docs) before my debug task.
pool:
vmImage: ubuntu-latest
stages:
- stage: Debug
displayName: Debug
jobs:
- deployment: Debug
displayName: Debug
strategy:
runOnce:
deploy:
steps:
# The Fix!
- checkout: self
- task: CmdLine@2
displayName: Debug
inputs:
script: |
echo 'Build.SourcesDirectory'
echo $(Build.SourcesDirectory)
ls -l $(Build.SourcesDirectory)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lukasz Dynowski |
