提问者:小点点

将azure文件共享装载到azure devops管道非常缓慢


目前,将azure文件共享装载到azure DevOps管道大约需要一分钟的时间。我想,这太长了。My pipelines包含装载操作的两个步骤:检索凭据和装载。

这就是我的管道的样子:

- task: AzureCLI@2
      inputs:
        azureSubscription: 'My Resource Group'
        scriptType: 'ps'
        scriptLocation: 'inlineScript'
        inlineScript: |
          (get-date).ToString('T')
          $sas_expiry = (Get-Date).AddHours($(storage.sas.expiry_hours)).ToUniversalTime().ToString("yyyy-M-d'T'H:M'Z'")
          echo "Getting keys..."
          (get-date).ToString('T')
          $key=(az storage account keys list --account-name $(storage.account) | jq '.[0].value' -r)
          echo "Keys are here."
          echo "##vso[task.setvariable variable=storage.key;issecret=true]$key"
          (get-date).ToString('T')
          $sas_key=(az storage account generate-sas --account-key $key --account-name $(storage.account) --expiry  $sas_expiry --https-only --permissions acdlpruw --resource-types sco --services f --output tsv)
          echo "##vso[task.setvariable variable=storage.sas.key;issecret=false]$sas_key"
          (get-date).ToString('T')
      displayName: Get azure file share credentials
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          $connectTestResult = Test-NetConnection -ComputerName mystorage.file.core.windows.net -Port 445
          if ($connectTestResult.TcpTestSucceeded) {
              cmd.exe /C "cmdkey /add:`"mystorage.file.core.windows.net`" /user:`"Azure\$(storage.account)`" /pass:`"$(storage.key)`""
              # Mount the drive
              New-PSDrive -Name $(storage.drive) -PSProvider FileSystem -Root "$(storage.unc)" -Persist
              dir z:
          }
          else {
              Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN, or Express Route to tunnel SMB traffic over a different port."
          }
      displayName: "Mount azure file share to Z"

... 很明显,我添加了一些时间戳输出,以便于“分析”。这是日志记录。

Starting: Get azure file share credentials
==============================================================================
Task         : Azure CLI
Description  : Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/Powershell Core/Batch script when running on Windows agent.
Version      : 2.0.5
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
C:\windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" --version"
WARNING: You have 2 updates available. Consider updating your CLI installation. Instructions can be found at https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
azure-cli                         2.0.80 *

command-modules-nspkg              2.0.3
core                              2.0.80 *
nspkg                              3.0.4
telemetry                          1.0.4

Extensions:
azure-devops                      0.17.0

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Program Files\Common Files\AzureCliExtensionDirectory'

Python (Windows) 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 02:47:15) [MSC v.1900 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal




Please let us know how we are doing: https://aka.ms/clihats
Setting AZURE_CONFIG_DIR env variable to: d:\a\_temp\.azclitask
Setting active cloud to: AzureCloud
C:\windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" cloud set -n AzureCloud"
C:\windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" login --service-principal -u *** -p *** --tenant ***"
[
  {
    "cloudName": "AzureCloud",
    "id": "3c8ec2e2-61cd-4554-bd9d-7e18817ef269",
    "isDefault": true,
    "name": "DevOps Experiments",
    "state": "Enabled",
    "tenantId": "***",
    "user": {
      "name": "***",
      "type": "servicePrincipal"
    }
  }
]
C:\windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" account set --subscription 3c8ec2e2-61cd-4554-bd9d-7e18817ef269"
C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'd:\a\_temp\azureclitaskscript1581554138338.ps1'"
12:36:15 AM
Getting keys...
12:36:15 AM
Keys are here.
12:36:21 AM
12:36:23 AM
C:\windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" account clear"
Finishing: Get azure file share credentials

... 对于步骤2:

Starting: Mount azure file share to Z
==============================================================================
Task         : PowerShell
Description  : Run a PowerShell script on Linux, macOS, or Windows
Version      : 2.163.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'd:\a\_temp\5ebb0c88-b7df-4c27-9dd3-51c6966ba590.ps1'"

CMDKEY: Credential added successfully.

Name           Used (GB)     Free (GB) Provider      Root                                               CurrentLocation
----           ---------     --------- --------      ----                                               ---------------
Z                  41.84       5078.16 FileSystem    \\mystorage.file.core.windows.n...                               

PSPath            : Microsoft.PowerShell.Core\FileSystem::Z:\builds
PSParentPath      : Microsoft.PowerShell.Core\FileSystem::Z:\
PSChildName       : builds
PSDrive           : Z
PSProvider        : Microsoft.PowerShell.Core\FileSystem
PSIsContainer     : True
Name              : builds
FullName          : Z:\builds
Parent            : 
Exists            : True
Root              : Z:\
Extension         : 
CreationTime      : 2/9/2020 8:28:26 PM
CreationTimeUtc   : 2/9/2020 8:28:26 PM
LastAccessTime    : 2/9/2020 8:28:26 PM
LastAccessTimeUtc : 2/9/2020 8:28:26 PM
LastWriteTime     : 2/9/2020 8:28:26 PM
LastWriteTimeUtc  : 2/9/2020 8:28:26 PM
Attributes        : Directory
Mode              : d-----
BaseName          : builds
Target            : 
LinkType          : 



Finishing: Mount azure file share to Z

所有这些都在默认的Microsoft Azure托管代理上运行。我可以做什么来更快地挂载文件共享?


共1个答案

匿名用户

检查az cli的任务日志,它实际上调用了powershell。exe执行az cli任务中的脚本。

因此,powershell任务中的脚本可以合并到az cli任务中。

在一个任务中执行脚本应该比在两个任务中执行脚本更快。

相关问题