Azure 管道:从 PowerShell 打印名称

Azure pipeline: print name from PowerShell

这是管道。 我想设置管道的名称,然后从 PowerShell 使用它。

name: $(Build.BuildId)-${{ variables['Build.SourceBranchName']}}

pool:
  vmImage: 'windows-latest'

trigger:
- '*'

steps:
- task: PowerShell@2
  displayName: Set version number in package.json
  inputs:
    targetType: 'inline'
    script: |
        Write-Host "name is $(name)"
        Get-ChildItem 'package.json' -Recurse  | Where { $_.FullName -notlike "*\node_modules\*" } | ForEach {
          (Get-Content $_ | ForEach  { $_ -replace '{BuildId}', '$(name)' }) | Set-Content $_
        }

但是微软说 :( 我发誓这在其他管道中有效——那是我从那里复制的!

name : The term 'name' 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 D:\a\_temp\d7eb3f23-73ea-4f8d-8945-d50c8822f24c.ps1:3 char:23
+ Write-Host "name is $(name)"
+                       ~~~~
    + CategoryInfo          : ObjectNotFound: (name:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException

名称存储为环境变量:

$env:BUILD_BUILDNUMBER