【发布时间】:2020-07-01 00:21:17
【问题描述】:
我正在尝试使用 powershell 脚本中的输出变量。我正在使用经典 UI 在线使用 Devops,并在发布管道中尝试了 powershell 4.* 和 Powershell 5.* 任务。
我正在使用一个自托管代理,它可以正常工作并执行许多其他构建和发布 powershell 的东西。 Azure Powershell 模块 3.5.0 版(目前不使用 4.x 是有原因的)。
为了简化,这里是我的测试内联脚本总...:
Write-Host '##vso[task.setvariable variable=MobileAppInsightsKey;isOutput=true;]thisisthekey'
Write-Host "This is host"
Write-Output '##vso[task.setvariable variable=MobileAppInsightsKey;isOutput=true;]thisisthekey'
Write-Output "This is output"
这是 Azure powershell 任务的输出。 (4.*)
2020-07-01T00:06:57.2970494Z ##[section]Starting: Azure PowerShell script: InlineScript
2020-07-01T00:06:57.3335882Z
==============================================================================
2020-07-01T00:06:57.3336692Z Task : Azure PowerShell
2020-07-01T00:06:57.3337292Z Description : Run a PowerShell script within an Azure environment
2020-07-01T00:06:57.3337566Z Version : 4.171.1
2020-07-01T00:06:57.3338039Z Author : Microsoft Corporation
2020-07-01T00:06:57.3338575Z Help : https://aka.ms/azurepowershelltroubleshooting
2020-07-01T00:06:57.3338930Z
==============================================================================
2020-07-01T00:06:58.5902105Z ## Validating Inputs
2020-07-01T00:06:58.5915067Z ## Validating Inputs Complete
2020-07-01T00:06:58.5924850Z ## Initializing Az module
2020-07-01T00:06:59.0747435Z ##[command]Import-Module -Name C:\Program
Files\WindowsPowerShell\Modules\Az.Accounts\1.9.0\Az.Accounts.psd1 -Global
2020-07-01T00:07:00.0802372Z ##[command]Clear-AzContext -Scope Process
2020-07-01T00:07:01.5597330Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2020-07-01T00:07:01.9691282Z ##[command]Connect-AzAccount -Identity @processScope
2020-07-01T00:07:03.1860248Z ##[command] Set-AzContext -SubscriptionId 5ec8ec06-XXXX-XXXX-XXXX- c0ff86c50e4 -TenantId ***
2020-07-01T00:07:03.9196710Z ## Az module initialization Complete
2020-07-01T00:07:03.9203692Z ## Beginning Script Execution
2020-07-01T00:07:03.9674782Z ##[command]& 'C:\DevOps\_work\_temp\1b1b130b-4306-448b-b4b2-e7daefc2382e.ps1'
2020-07-01T00:07:03.9974844Z This is host
2020-07-01T00:07:04.0101140Z This is output
2020-07-01T00:07:04.0517610Z ##[command]Disconnect-AzAccount -Scope Process -ErrorAction Stop
2020-07-01T00:07:04.4795714Z ##[command]Clear-AzContext -Scope Process -ErrorAction Stop
2020-07-01T00:07:04.9468120Z ## Script Execution Complete
2020-07-01T00:07:04.9857991Z ##[section]Finishing: Azure PowerShell script: InlineScript
请注意,“This is Host”和“This is Output”都显示,但“##vso[....”不显示。
我在后续步骤中尝试读取的 MobileAppInsightsKey 也是空的(未初始化)。
希望有人能指出我正确的方向。
谢谢,马克。
【问题讨论】:
标签: azure azure-devops azure-powershell