azure - 如何在 Azure 经典发布管道中使用 Powershellscript - 存储在 Azure Devops 安全文件中的脚本文件

标签 azure azure-devops azure-pipelines-release-pipeline azure-rm-template azure-pipelines-release-task

我正在 ARM 模板中使用 VM 的自定义脚本扩展:

         {
   "type": "Microsoft.Compute/virtualMachines/extensions",
 "name": "[concat(parameters('vm-Name'),'-0',copyIndex(1),'/script')]",
   "apiVersion": "2015-05-01-preview",
   "location": "[resourceGroup().location]",
      "copy": {
                "name": "storagepoolloop",
                "count": "[parameters('virtualMachineCount')]"
            },
   "dependsOn": [
       "virtualMachineLoop",
       "nicLoop"
   ],
   "properties": {
       "publisher": "Microsoft.Compute",
       "type": "CustomScriptExtension",
       "typeHandlerVersion": "1.4",
       "settings": {
           "fileUris": [

       ],
      "commandToExecute": "[parameters('commandToExecute')]"
     }
   }
 }

其中参数=“powershell.exe $(Agent.TempDirectory)/$(script.secureFilePath)”

我正在使用 azure devops 安全文件来存储我的脚本。我在部署虚拟机之前下载了安全文件任务。 我也尝试过直接引用脚本文件名 “powershell.exe $(Agent.TempDirectory)/puscript.ps1”

我正在使用经典的发布管道,如果这不是正确的方法,请指导如何使用存储在安全文件中的 powershell 脚本。

感谢任何帮助。提前致谢。

最佳答案

该脚本需要下载到您正在创建的 VM 上,而不是下载到正在部署 ARM 的计算机上。在虚拟机启动扩展之前,该命令实际上不会执行,因此变量 $(Agent.TempDirectory) 引用执行管道的计算机上的目录,并且在虚拟机启动时不会存在.

我通过将脚本包含在用于创建 VM 的镜像中,对 VM 自定义扩展执行了相同的操作。如果您不使用自定义镜像,则可以添加存储帐户信息以在 protectedSettings 中下载它,如下所示:

"protectedSettings": {
    "commandToExecute": "powershell.exe puscript.ps1",
    "storageAccountName": "yourstorageaccount",
    "storageAccountKey": "<account key>",
    "fileUris": [
        "https://yourstorageaccount.blob.core.windows.net/container/puscript.ps1"
    ]
}

引用:https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows#extension-schema

关于azure - 如何在 Azure 经典发布管道中使用 Powershellscript - 存储在 Azure Devops 安全文件中的脚本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71965120/

相关文章:

azure - 批准 AAD 租户中的单个应用程序以防止 AADSTS90093 错误

docker - 在Dockerfile中动态注册环境变量

azure-devops - 如何使用不记名 token 从 Azure DevOps 调用 REST API

azure-devops - Service Fabric 应用程序部署超时

azure - 您能否在 Azure DevOps 中触发 CD 管道之前组合多个 CI 构建?

azure - Azure DocumentDB 如何扩展?我需要担心吗?

azure - 如何在 AAD 中同意应用程序及其依赖服务

azure - Azure 机器学习工作室中的标签编码

azure - 无法获取 Azure 成本消耗 api 的 Azure 范围

.net - 如何停止 dotnet pack 在 azure devops 中构建项目(--no-build 没有效果)