0

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.

1
  • Hi BlueBSH, any update on this, have you checked my answer? Does it answer your question? Commented Jul 26, 2022 at 15:10

2 Answers 2

1

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

enter image description here

change dir

cd $(System.DefaultWorkingDirectory)/$(Release.PrimaryArtifactSourceAlias)
ls

Then you can locate code. enter image description here

Release variables documentation:
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch

Sign up to request clarification or add additional context in comments.

Comments

0

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:

enter image description here

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:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.