'Get current path to -what- triggered the pipeline (Yaml)
I've tried to echo / debug most of the variables here https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml but none of them shows -what- triggered the pipeline.
If MyDir is a directory tree with n subdirectories containing files, I want to know what file actually triggered my pipeline (path to file)
trigger:
paths:
include:
- MyDir/*
I use Git, and I have experimented with Git log but
git diff HEAD HEAD~ --name-only seems to produce somewhat ok results.
Any ideas?
UPDATE I ended up doing a Bash script that iterates over the files in the current commit. I needed them in a later step
Solution 1:[1]
But if two commits happens at the same time I still don't know what actually triggered my pipeline.
It's not clear how you implemented two commits at the same time.
You could using following task with Git command to list the changes files:
- powershell: |
## get the changed files
$files=$(git diff HEAD HEAD~ --name-only)
$temp=$files -split ' '
$count=$temp.Length
echo "Total changed $count files"
$files | ForEach-Object {
echo $_
}
If you enable CI, each commit will start a separate build, then we will get the modified file name and path in each build.
If you submit a commit locally, and each commit contains multiple files that are modified, we can use the ForEach loop to output the list and path of the modified file names?
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 | Leo Liu-MSFT |


