According to the documentation, there are a bunch of predefined variables available for the tasks which run in an environment for Release Management. How do I access these variables from within a Powershell script?
For example: the System.TeamProject
variable is defined, and should return the current TFS TeamProject. However, when I write:
Write-Host "environment var: $env:System.TeamProjectId"
The output in the log file is:
2016-06-07T09:26:49.5537161Z environment var: release.TeamProject
However, in the Initialize
log file, the following is displayed:
4 2016-06-07T09:26:40.4121001Z Environment variables available are below. Note that these environment variables can be referred to in the task (in the ReleaseDefinition) by replacing "_" with "." e.g. AGENT_NAME environment variable can be referenced using Agent.Name in the ReleaseDefinition:
...
34 2016-06-07T09:26:40.4277002Z [SYSTEM_COLLECTIONID] --> [2043d9ba-7ec9-43f0-8e6c-96a8b28f55d8]
35 2016-06-07T09:26:40.4277002Z [SYSTEM_TEAMPROJECTID] --> [9718773d-2aee-4625-91c6-80de16301479]
36 2016-06-07T09:26:40.4277002Z [SYSTEM_TEAMPROJECT] --> [MyProject]
37 2016-06-07T09:26:40.4277002Z [SYSTEM_CULTURE] --> [en-US]
So this means the variable is there. I tried $(System.TeamProject)
as suggested somewhere else, but that fails with The term ... is not recognized
-error.
Also, the variables which I have configured myself in the Release Definition, e.g. priority
, I am able to access with $env:priority
.
As a workaround I can create my own parameters in the script, and pass them in the Arguments field in the task definition, but this kind of defeats the purpose.
Use curly braces because the variable name contains .
. Example:
PS C:\> ${Env:System.TeamProject} = "Var contents"
PS C:\> ${Env:System.TeamProject}
Var contents
PS C:\> Write-Host "Prefix - $Env:System.TeamProject"
Prefix - .TeamProject
PS C:\> Write-Host "Prefix - ${Env:System.TeamProject}"
Prefix - Var contents