簡體   English   中英

PowerShell 任務未在 Azure 管道中運行腳本?

[英]PowerShell Task not running the script in Azure Pipelines?

I have a powershell task that is used to run a script which involves creating azure resources (Example: Resource group, Azure Key Vault, Function App...). 當管道正在運行並到達部署階段的 powershell 任務時,它會顯示以下消息:

在此處輸入圖像描述

這里的問題是 Finishing:Powershell 但它沒有執行腳本也沒有創建任何 azure 資源。

這是 powershell 腳本的示例:

$vaultName = "key vault name"
$blobstorageName = "blob storage name"
$Location = "Location Name"
$resourceGroupName = "Resource Group Name"

try {

    #Creation of Resource Group
    $resourceGroup = Get-AzResourceGroup -ResourceGroupName $resourceGroupName -ErrorAction SilentlyContinue 

    if($null -eq $resourceGroup)
    {
        New-AzResourceGroup -Name $resourceGroupName -Location $Location
    }

    else
    {
        Write-Host "The ResourceGroup with the name: $resourceGroupName already exists."
    }

    # Creation of Storage Account

    $checkBlobStorage = (Get-AzStorageAccountNameAvailability -Name $blobstorageName) | Select-Object NameAvailable
    if ($checkBlobStorage.NameAvailable)
    {
        New-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $blobstorageName -Location $Location -SkuName Standard_LRS -Kind StorageV2 -AccessTier Hot
    }

    else 
    {
        Write-Host "The name $blobStorageName is not available. Suggest a new globally unique name!"
    }


catch 
{

}

有誰知道出了什么問題? Am I missing something in the powershell script (Maybe I don't have direct access to the azure portal from azure devops) or maybe something is missing in the Yaml file?

兩個主要問題:

  1. 您似乎正在使用Powershell 任務,它不是為與 Azure 通信而設計的。 對於這種腳本,您應該使用Azure Powershell 任務,因為它已經加載了正確的模塊並准備好了身份驗證。
  2. 您的腳本正在吞噬錯誤,因此它隱藏了問題所在。 捕獲異常通常更有用; 如果您的腳本出錯,則讓它出錯,並讓管道在其日志中向您顯示發生了什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM