Reputation: 401
In my local source repo, I have a bunch of power shell scripts that will need to execute as part of a release job.
In order to get them to be executed by the deployment agent, what is the correct way to get the scripts where they need to be and reference them? Do I need to copy the scripts into an artifact and retrieve that artifact on the deploy agent side, or is there another way to do this? All MS documentation says use $(System.DefaultWorkingDirectory) as my base path but on the deployment side the scripts aren't copied to there since it does not download the repo. I am assuming making a artifact and downloading it is the correct way to do this, then they would be in that location.
Upvotes: 0
Views: 536
Reputation: 7251
In build pipeline:
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/xxx.ps1' # Put all of the powershell script files here.
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
In release pipeline:
steps:
- task: ExtractFiles@1
displayName: 'Extract files '
inputs:
destinationFolder: '$(System.ArtifactsDirectory)'
cleanDestinationFolder: false
steps:
- powershell: |
# Write your PowerShell commands here.
Write-Host "Hello World"
cd $(System.ArtifactsDirectory)
dir
displayName: 'PowerShell Script'
Get the ps1 file:
Upvotes: 0
Reputation: 3592
You can use a download Repository artifact on your release pipeline and then use the predefined release variables in order to cd into that directory.System.DefaultWorkingDirectory
change dir
cd $(System.DefaultWorkingDirectory)/$(Release.PrimaryArtifactSourceAlias)
ls
Release variables documentation:
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch
Upvotes: 1