【问题标题】:New Issue with PowerShell Task in Azure PipelineAzure Pipeline 中 PowerShell 任务的新问题
【发布时间】:2021-07-30 02:17:12
【问题描述】:

我在 Azure DevOps 管道中遇到了 PowerShell 任务的新问题。该任务最后一次运行是在 4/27 没有问题,而当前问题发生在下一个版本 5/5。在此期间,没有对管道进行任何更改。

问题似乎源于任务本身,因为它发生在我们的构建和部署管道中的 PowerShell 任务中。其他可能相关的信息,管道在自托管代理上运行并从 Azure DevOps Server 2019 触发。

这是我们正在运行的任务脚本:

Write-Host "##vso[build.addbuildtag]Deploy" 

这是 YAML:

steps:

- task: PowerShell@1

  displayName: 'PowerShell Script'

  inputs:

    scriptType: inlineScript

    inlineScript: 'Write-Host "##vso[build.addbuildtag]Deploy" '

    failOnStandardError: false

  continueOnError: true

  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))

这是产生的错误:

##[debug]Evaluating condition for step: 'PowerShell Script'
##[debug]Evaluating: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
##[debug]Evaluating and:
##[debug]..Evaluating succeeded:
##[debug]..=> True
##[debug]..Evaluating eq:
##[debug]....Evaluating indexer:
##[debug]......Evaluating variables:
##[debug]......=> Object
##[debug]......Evaluating String:
##[debug]......=> 'Build.SourceBranch'
##[debug]....=> 'refs/heads/master'
##[debug]....Evaluating String:
##[debug]....=> 'refs/heads/master'
##[debug]..=> True
##[debug]=> True
##[debug]Expanded: and(True, eq('refs/heads/master', 'refs/heads/master'))
##[debug]Result: True
##[section]Starting: PowerShell Script
==============================================================================
Task         : PowerShell
Description  : Run a PowerShell script
Version      : 1.2.3
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
##[debug]Working directory: 'D:\DevOps_LegacyAgent\_work\1\s'
##[debug]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "try { $null = [System.Security.Cryptography.ProtectedData] } catch { Write-Verbose 'Adding assemly: System.Security' ; Add-Type -AssemblyName 'System.Security' ; $null = [System.Security.Cryptography.ProtectedData] ; $Error.Clear() } ; Invoke-Expression -Command ([System.Text.Encoding]::UTF8.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String('AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAArARvThIFVke20pF03HsjGQAAAAACAAAAAAADZgAAwAAAABAAAACogvvpDqu82/uBaGAzfMLmAAAAAASAAACgAAAAEAAAAMmlYwLrG+pX6cojbe/JSEdgAAAAnSbu0YpvQYBRJpACag4t6eYLxZ38eidUUEp2oqJQg8E5SHMJTn66QrqAz0Ks0C8hGYESnkfwEIv9GdI6/stDqX0YXpR7Xvus30Hl8D3QJPfRFeugZ0es+1SdZkofp4TuFAAAANt4kYo56dv5uoAgUYZvimImJ7Td'), [System.Convert]::FromBase64String('ixGPc4PRq3A7+cJJCfL97g=='), [System.Security.Cryptography.DataProtectionScope]::CurrentUser))) ; if (!(Test-Path -LiteralPath variable:\LastExitCode)) { Write-Verbose 'Last exit code is not set.' } else { Write-Verbose ('$LastExitCode: {0}' -f $LastExitCode) ; exit $LastExitCode }"
##[command]. 'C:\Users\SAC00_DevOps_GADBld\AppData\Local\Temp\d564f4d3-aa11-40b4-a1f4-f6ef44aaa197.ps1' 
##[error]Exception calling "Unprotect" with "3" argument(s): "The operation completed successfully.
"
At line:1 char:237
+ ... Clear() } ; Invoke-Expression -Command ([System.Text.Encoding]::UTF8. ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CryptographicException
 

##[error]Process completed with exit code 0 and had 1 error(s) written to the error stream.
##[debug]System.Exception: Process completed with exit code 0 and had 1 error(s) written to the error stream.
   at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.PowerShellExeHandler.RunAsync()
   at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()
   at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
##[section]Finishing: PowerShell Script

【问题讨论】:

    标签: powershell azure-pipelines azure-devops-pipelines


    【解决方案1】:

    尝试以下方法:

    另外,添加Add-Type -AssemblyName System.Security

    steps:
    
    - task: PowerShell@1
    
      displayName: 'PowerShell Script'
    
      inputs:
    
        scriptType: inlineScript
    
        inlineScript: |
    
         Add-Type -AssemblyName System.Security
         
         Write-Host "##vso[build.addbuildtag]Deploy" 
    
        failOnStandardError: false
    
      continueOnError: true
    
      condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
    

    【讨论】:

      【解决方案2】:

      我能够通过切换到 Powershell 任务的 v2 (PowerShell@2) 来解决此问题

      【讨论】:

        猜你喜欢
        • 2020-10-05
        • 1970-01-01
        • 2021-12-01
        • 2020-07-27
        • 2018-08-21
        • 2021-11-04
        • 2020-06-11
        • 2022-06-13
        • 2020-09-28
        相关资源
        最近更新 更多