Nathan
Nathan

Reputation: 915

How do I run a Powershell script from a second Repository in a different Build?

I want to have a centralized repo for some Powershell scripts that I want to share with multiple Builds and Releases.

I wanted to have a Powershell Task that calls one of those scripts in a Build. How can I go about doing this?

Upvotes: 1

Views: 2318

Answers (2)

Leo Liu
Leo Liu

Reputation: 76928

How do I run a Powershell script from a second Repository in a different Build?

The answer is yes.

You could add a command line task in the build pipeline of first Repository to clone the second Repository by the git command line:

git config --global user.email "[email protected]"
git config --global user.name "Admin"

git clone <repo> <directory>

With this task, we cloned the powershell scripts to current default working directory, then we could execute this powershell scripts.

Then add add powershell task to call one of those scripts in a Build, in the Script Path, we need to specify the path like following:

$(System.DefaultWorkingDirectory)\<SecondRepositoryName>\<PSFolder>\TestPS.ps1

Note:

When you use git clone to clone the repo, you need to provide your certificate in your source link, usually using PAT:

enter image description here

The link looks like:

https://<OrganizationName>@dev.azure.com/<OrganizationName>/MyTestProject/_git/Test

Then we need to replace the first OrganizationName with PAT. So, it will be:

https://<PAT>@dev.azure.com/<OrganizationName>/MyTestProject/_git/Test

As test, it works fine on my side, you can check if it works for you.

Hope this helps.

Upvotes: 3

Thiago Custodio
Thiago Custodio

Reputation: 18387

I think you're looking for Azure Artifacts. Take a look on this: https://learn.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops

Upvotes: -1

Related Questions