管道两次调用同一Powershell函数,将无法识别对函数的第一次调用

时间:2019-05-08 11:13:32

标签: powershell azure-devops

我的管道如下:

trigger:
- master

jobs:
- job: BuildDacPac
  steps:
  - task: MSBuild@1
    displayName: 'Build DACPAC'
    inputs:
      solution: 'AzureDevops-Fa-Snapshot-CI-Pipeline-Adv.sln'
      msbuildArguments: '/property:OutDir=bin\Release'

- job: RefreshIntegrationTestDb
  dependsOn: BuildDacPac
  workspace:
    clean: all
  steps:
  - powershell: |
      $securePassword = ConvertTo-SecureString -String '$(pfaPassword)' -AsPlainText -Force
      $pfaCreds = New-Object System.Management.Automation.PSCredential '$(pfaUsername)', $securePassword
      Invoke-PfaDbRefresh -RefreshDatabase $(refreshDatabase) `
                          -RefreshSource   $(refreshSource) `
                          -DestSqlInstance Z-STN-WIN2016-A\DEVOPSIAT `
                          -PfaEndpoint     $(pfaEndpoint) `
                          -PfaCredentials  $pfaCreds

- job: DeployDacPac
  dependsOn: RefreshIntegrationTestDb
  steps:
  - script: sqlpackage.exe /Action:Publish /SourceFile:"$(System.DefaultWorkingDirectory)\AzureDevOps-Fa-Snapshot-Ci-Pipeline-Adv\bin\Release\AzureDevOps-Fa-Snapshot-Ci-Pipeline-Adv.dacpac" /TargetConnectionString:"server=$(iatInstanceName);database=$(refreshDatabase)" 

- job: ParallelDevDatabaseRefresh
  dependsOn: RefreshIntegrationTestDb
  pool: $(agentPool)
  strategy: 
    matrix:
      dev_1:
        instanceName: Z-STN-WIN2016-A\DEVOPSDEV1
      dev_2:
        instanceName: Z-STN-WIN2016-A\DEVOPSDEV2
      dev_3:
        instanceName: Z-STN-WIN2016-A\DEVOPSDEV3
      dev_4:
        instanceName: Z-STN-WIN2016-A\DEVOPSDEV4
  steps:
  - powershell: |
      $securePassword = ConvertTo-SecureString -String '$(pfaPassword)' -AsPlainText -Force
      $pfaCreds = New-Object System.Management.Automation.PSCredential '$(pfaUsername)', $securePassword
      Invoke-PfaDbRefresh -RefreshDatabase $(refreshDatabase) `
                          -RefreshSource   $(refreshSource) `
                          -DestSqlInstance $(instanceName) `
                          -PfaEndpoint     $(pfaEndpoint) `
                          -PfaCredentials  $pfaCreds

在作业ParallelDevDatabaseRefresh中对Invoke-PfaDbRefresh的调用工作正常,但是没有任何问题,但是在RefreshIntegrationTestDb作业中对该函数的调用失败:

##[section]Starting: PowerShell
==============================================================================
Task         : PowerShell
Description  : Run a PowerShell script on Windows, macOS, or Linux.
Version      : 2.148.0
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
Generating script.
========================== Starting Command Output ===========================
[command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/home/vsts/work/_temp/022ae053-d678-4d53-9f14-48a828a2d619.ps1'
refreshDatabase : The term 'refreshDatabase' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At /home/vsts/work/_temp/022ae053-d678-4d53-9f14-48a828a2d619.ps1:4 char:40
+ Invoke-PfaDbRefresh -RefreshDatabase $(refreshDatabase) `
+                                        ~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (refreshDatabase:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException

##[error]PowerShell exited with code '1'.
##[section]Finishing: PowerShell

我正在努力理解为什么管道可以在管道的一部分而不是另一部分中识别powershell函数调用。

1 个答案:

答案 0 :(得分:0)

经过很多挫折之后,我找到了最底端,对Invoke-PfaDbRefresh的调用所在的部分中包含以下行:

pool: $(agentPool)

对无效的函数的调用不包括该行,因此默认情况下使用从Azure托管的Ubuntu池中使用生成代理。