是否可以在Powershell中编写自定义Azure DevOps任务



我们使用Azure DevOps Server 2019(在prem上(。

我想在Powershell中编写一个自定义的Azure DevOps任务。到目前为止,我在网上看到的例子都是关于用Typescript编写的。

我想知道——这是唯一的办法吗?例如,我们可以使用Powershell吗?

是的,您可以在自定义生成任务中使用PowerShell。

您需要在task.json:中编辑此部分

"execution": {
"PowerShell3": {
"target": "ps-script.ps1",
"workingDirectory": "$(currentDirectory)"
}
}

您需要安装VstsTaskSdkPowershell模块:

  • 打开Powershell
  • 导航到您的扩展目录的root/buildtask
  • 执行mkdir ps_modules,然后导航到新目录
  • 你的pwd应该读成root/buildtask/ps_modules
  • 执行Save-Module -Name VstsTaskSdk -Path .,将模块保存到磁盘
  • 通过删除版本号来展平目录结构。例如,您将有一个root/buildtask/ps_modules/VstsTaskSdk/0.10.0/*的路径,现在应该读作root/buildtask/ps_modules/VstsTaskSdk/*

这里有完整的教程。

您还可以在这个GitHub repo上看到一个带有PS的自定义任务示例。

注意:它只适用于windows机器

是的,您可以在自定义任务中直接使用PS脚本。您可以通过以下方式配置task.json

"execution": {
"PowerShell3": {
"target": "script.ps1",
"workingDirectory": "$(currentDirectory)"
}
}

最新更新