Here is the pipeline. I want to set the pipeline's name and then use it from 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 $_
}
But Microsoft says no :( I swear this worked in an other pipeline -- that's where I copied it from!
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
CodePudding user response:
The name is stored as an environment variable:
$env:BUILD_BUILDNUMBER