Reputation: 62712
We use Azure DevOps Server 2019 (on-prem).
I would like to author a custom Azure DevOps task in Powershell. The examples I have seen so far on the web are about authoring it in Typescript.
I wonder - is it the only way? Can we use Powershell, for instance?
Upvotes: 0
Views: 242
Reputation: 41545
Yes, you can use PowerShell in your custom build task.
You need to edit this section in task.json
:
"execution": {
"PowerShell3": {
"target": "ps-script.ps1",
"workingDirectory": "$(currentDirectory)"
}
}
And you need to install the VstsTaskSdk
Powershell Module:
root/buildtask
of directory of your extensionmkdir ps_modules
and then navigate into the new directorypwd
should read root/buildtask/ps_modules
Save-Module -Name VstsTaskSdk -Path .
which will save the module to disk.root/buildtask/ps_modules/VstsTaskSdk/0.10.0/*
which should now read root/buildtask/ps_modules/VstsTaskSdk/*
A full tutorial exist here.
You can also see an example for custom task with PS on this GitHub repo.
Note: it works only in windows machines.
Upvotes: 1
Reputation: 31003
Yes, you can use the PS script directly in your custom task. You can configure task.json
in this way:
"execution": {
"PowerShell3": {
"target": "script.ps1",
"workingDirectory": "$(currentDirectory)"
}
}
Upvotes: 1