[英]How to get the TeamCity working dir in a powershell build step
In my TeamCity project I have a PowerShell build step, I need to get the current working dir of team city in the script.在我的 TeamCity 项目中,我有一个 PowerShell 构建步骤,我需要在脚本中获取团队城市的当前工作目录。 I tried this code to get it from the environment variables, however, the environment variable is apparently
null
:我尝试使用此代码从环境变量中获取它,但是,环境变量显然是
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?如何访问 TeamCity 变量,或者如何获取 TeamCity 项目的当前工作路径?
According to TeamCity documentation , there are no environment variable for the teamcity.build.workingdirectory
-property.根据 TeamCity 文档,
teamcity.build.workingdirectory
-property 没有环境变量。
System Property Name : teamcity.build.workingDir
系统属性名称: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.
这是 TeamCity 构建运行程序应该启动进程的路径。 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.您可以尝试返回 PowerShell 的当前工作目录的
$pwd
或Get-Location
。 Hopefully the PowerShell process was started in the same working directory as the build-runner.希望 PowerShell 进程是在与构建运行程序相同的工作目录中启动的。 Ex:
前任:
"Working Dir: " + $pwd
"Working Dir: " + (Get-Location)
$myDirectory = Split-Path $MyInvocation.MyCommand.Path
For your PowerShell build step, you can make that set an environment variable before running your code.对于您的 PowerShell 构建步骤,您可以在运行代码之前设置环境变量。 eg if you normally want to run
my-script.ps1
you can change the build step to "source code" and then use something like例如,如果您通常想运行
my-script.ps1
,您可以将构建步骤更改为“源代码”,然后使用类似
$env:TEAMCITY_BUILD_WORKINGDIR = "%teamcity.build.workingDir%"
. "./my-script.ps1"
Then you can use $env:TEAMCITY_BUILD_WORKINGDIR
inside of your script(s).然后,您可以在脚本中使用
$env:TEAMCITY_BUILD_WORKINGDIR
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.