4
votes

I have a PowerShell script that I want to re-use across multiple build pipelines. My question is, is there a way I can "store" or "save" my PowerShell script at the project or organization scope so that I can use it in my other build pipelines? If so, how? I can't seem to find a way to do this. It would be super handy though.

5

5 Answers

0
votes

From what I have seen, no.

A few different options I have explored are:

  • If using a non-hosted agent, saving the file onto the build server. Admittedly this doesn't scale well, but it is better than copy/pasting the script all over. I was able to put these scripts into version control and deploy them via their own pipeline so that might be an solution for scaling (if necessary)
  • Cloning another repository that has these shared scripts during the process.

I've been asking for this feature for a bit, but it seems the Azure DevOps team has higher priorities.

0
votes

Depending on how big theese scripts are you can create Taskgroups that contain powershell-tasks with the script as inline-powershell. But this only works on project-scope..

Another attempt i'd try would be to create a repo containing your powershell-scripts, add this repo as submodule in the repository you are trying to build and then call the scripts from the submodule-folder. But this only works when using git-repos.

Or you could create a custom build-task that contains your script.

0
votes

How about putting the powershell in a nuget package and install that in depending projects?

0
votes

I just discovered YAML templates (https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azdevops#step-re-use).

I think it may help you in this case (depending how large it is your file), you can put an inline powershell script in that template yaml, and reuse it on your main yaml.

Documentation is pretty straightforward.

0
votes

It is now possible to check out multiple repositories in one YAML pipeline. You could place your script in one repository and check it out in a pipeline of any other repository. You could then reference the script directly on the pipeline workspace.

More info here.