4

I have yaml file for the azure pipline in a repo. And I need to run powershell script from a different repo.

As far as I understood I can add side repo to resources section in yaml and then use task:ShellScript@2 with scriptPath parameter. But as I understood it works relatively for repo in which yaml is placed. And I'm not sure how can I access file from a different repo.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Cheephs
  • 69
  • 1
  • 7
  • If I understood correctly, the only way is to get that file in some way. For exameple 1. The other repo "releases" the file and store it somewhere - 2. you do `git clone` to the other repo from your pipeline – Carlos Garcia Jun 02 '21 at 08:59
  • Yeah I have a repo in azure DevOps where script is stored. Lets call it `AppRepo`. And I have second one with yaml file. Let's call it `BuildRepo` As I understood from [docs](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/resources?view=azure-devops&tabs=schema#resources-pipelines) we can add `AppRepo` via resources section. But I can't figure out how can I reference any file (in my case shellscript) from this repo? Maybe there some specific syntax or something? – Cheephs Jun 02 '21 at 09:11
  • So you need files from both repos? or you only need files from AppRepo? If you need files from both, you cannot just reference as far as I know. From `BuildRepo` you can get the artifact (output) of a pipeline in the `AppRepo` - so I would create a pipeline in `AppRepo` that `publish` the file as an artifact. then you can consume it from `BuildRepo` pipelines – Carlos Garcia Jun 02 '21 at 09:54
  • "From BuildRepo you can get the artifact (output) of a pipeline in the AppRepo - so I would create a pipeline in AppRepo that publish the file as an artifact." Yes, that's what I'm trying to do. I have a pipline that publishes build results from `AppRepo` and then I want to add this to a yaml in `BuildRepo` and reference PS file from it? Is it possible? – Cheephs Jun 02 '21 at 10:16
  • How about the Krzysztof Madej`s answer? It should be the solution for your question. If not, would you please let me know the latest information about this issue? – Leo Liu Jun 03 '21 at 06:23

1 Answers1

7

Yes, you have to use repository resource and checkout that repo as follows:

resources:
  repositories:
    - repository: devops
      type: github
      name: kmadof/devops-templates
      endpoint: kmadof


steps:
- checkout: self
- checkout: devops
- task: ShellScript@2
  inputs:
    scriptPath: $(Agent.BuildDirectory)/devops/scripts/some-script.sh
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107