[ad_1]
I have an Azure DevOps pipeline that executes a Powershell task to create artifacts for each changed file after a pull request is submitted. However, I am not able to return modified/new files in order to create these artifacts. When I test locally I have no problem grabbing the modified file name, but within the pipeline itself the returned result is blank/empty:
$changes = git diff --name-only --relative --diff-filter=M origin/master --name-only -- .
Full .yml Code:
trigger:
- master
pool:
vmImage: windows-latest
jobs:
- job: get_changed_files
steps:
- task: [email protected]
inputs:
targetType: 'inline'
script: |
$targetfolder = "$(Build.StagingDirectory)" + "/"
function CopyFiles{
param( [string]$source )
$target = $targetfolder + $source
New-Item -Force $target
copy-item $source $target -Force
}
$changes = git diff --name-only --relative --diff-filter=M origin/master --name-only -- .
write-host "test"
$changes
if ($changes -is [string]){ CopyFiles $changes }
else
{
if ($changes -is [array])
{
foreach ($change in $changes){ CopyFiles $change }
}
}
- task: [email protected]
inputs:
pathToPublish: $(Build.StagingDirectory)
artifactName: MyChangedFiles
[ad_2]