Reusing PowerShell Scripts in Azure DevOps

Viewed 2367

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 Answers

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.

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.

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.

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

Related