Reputation: 19329
In my TeamCity project I have a PowerShell build step, I need to get the current working dir of team city in the script. I tried this code to get it from the environment variables, however, the environment variable is apparently null
:
"Working Dir: " + $env:teamcity_build_workingDir
How can I access the TeamCity variables, or how can I get the current working path of the TeamCity project?
Upvotes: 1
Views: 3924
Reputation: 29573
For your PowerShell build step, you can make that set an environment variable before running your code. e.g. if you normally want to run my-script.ps1
you can change the build step to "source code" and then use something like
$env:TEAMCITY_BUILD_WORKINGDIR = "%teamcity.build.workingDir%"
. "./my-script.ps1"
Then you can use $env:TEAMCITY_BUILD_WORKINGDIR
inside of your script(s).
Upvotes: 0
Reputation: 54821
According to TeamCity documentation, there are no environment variable for the teamcity.build.workingdirectory
-property.
System Property Name: teamcity.build.workingDir
Environment Variable Name: none
Description: Working directory where the build is started. This is a path where TeamCity build runner is supposed to start a process. This is a runner-specific property, thus it has different value for each new step.
You could try $pwd
or Get-Location
which returns PowerShell's current working directory. Hopefully the PowerShell process was started in the same working directory as the build-runner. Ex:
"Working Dir: " + $pwd
"Working Dir: " + (Get-Location)
Upvotes: 4