[英]TFS 2015 Build Step using PS environment variables fails
I have a vNext build step that runs a PowerShell script after MSBuild. 我有一个vNext构建步骤,可在MSBuild之后运行PowerShell脚本。 I'm getting this error:
我收到此错误:
[error]BUILD_SOURCESDIRECTORY : The term 'BUILD_SOURCESDIRECTORY' is not recognized as the name of a cmdlet, function, script file, or operable program.
[错误] BUILD_SOURCESDIRECTORY:术语“ BUILD_SOURCESDIRECTORY”未被识别为cmdlet,函数,脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。
...
...
[error]BUILD_BUILDNUMBER : The term 'BUILD_BUILDNUMBER' is not recognized as the name of a cmdlet, function, script file, or operable program.
[错误] BUILD_BUILDNUMBER:术语“ BUILD_BUILDNUMBER”未被识别为cmdlet,函数,脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。
Here's the script: 这是脚本:
if([string]::IsNullOrEmpty($BuildNumber)){
$BuildNumber = $Env:TF_BUILD_BUILDNUMBER
}
if([string]::IsNullOrEmpty($SolutionRoot)){
$SolutionRoot = $Env:TF_BUILD_SOURCESDIRECTORY
}
Write-Output "-BuildName: $BuildNumber"
Write-Output "-BuildRoot: $SolutionRoot"
The script has not changed in weeks. 该脚本在几周内没有更改。 The build definition has not changed in months.
构建定义在几个月内没有改变。 TFS was updated last night with updates 1 and 2:
昨晚更新了TFS,其中包含更新1和2:
I tried doing another build, but it had the same exact issue, so it's not a first-pancake type of issue. 我尝试进行另一次构建,但是它具有相同的确切问题,因此它不是第一手的类型的问题。 I can't find what the update might have done to the environment variables to make them unrecognizable.
我找不到对环境变量进行更新以使其无法识别的操作。
I'd appreciate any ideas, and I know how to mark an answer! 我将不胜感激任何想法,而且我知道如何标记答案! =)
=)
Update: I tried removing the TF_, but it failed with identical errors 更新:我尝试删除TF_,但是由于相同的错误而失败
$BuildNumber = $Env:BUILD_BUILDNUMBER
$SolutionRoot = $Env:BUILD_SOURCESDIRECTORY
Update We did get this working again, but I still have no idea why things went from working to not working overnight. 更新我们确实再次使它工作了,但是我仍然不知道为什么事情会从工作变成一夜不工作。 The TFS updates had to play a role.
TFS更新必须发挥作用。
Nothing about using PS environment variables changed during the update. 在更新过程中,关于使用PS环境变量的任何更改都没有改变。 Test pass with my TFS 2015update2.
我的TFS 2015update2通过测试。
Try again with below: 请尝试以下操作:
change $BuildNumber = $Env:TF_BUILD_BUILDNUMBER
to $BuildNumber = $Env:BUILD_BUILDNUMBER
将
$BuildNumber = $Env:TF_BUILD_BUILDNUMBER
为$BuildNumber = $Env:BUILD_BUILDNUMBER
change $SolutionRoot = $Env:TF_BUILD_SOURCESDIRECTORY
to $SolutionRoot = $Env:BUILD_SOURCESDIRECTORY
将
$SolutionRoot = $Env:TF_BUILD_SOURCESDIRECTORY
为$SolutionRoot = $Env:BUILD_SOURCESDIRECTORY
Ok, my build is working again because I adjusted in the TFS Build definition how arguments get passed into the PS script. 好的,我的构建再次正常工作,因为我在TFS Build定义中调整了参数如何传递到PS脚本中。 I think there were two slightly different issues at play.
我认为有两个稍微不同的问题在起作用。
Here's what worked on TFS 2015 Base in the PS Arguments field: 以下是PS Arguments字段中在TFS 2015 Base上工作的内容:
-SolutionRoot $(BUILD_SOURCESDIRECTORY) -BuildNumber $(BUILD_BUILDNUMBER)
Here's what works on TFS 2015 Update 2 in the PS Arguments field: 这是在PS Arguments字段中的TFS 2015 Update 2上有效的方法:
-SolutionRoot $(Build.SourcesDirectory) -BuildNumber $(Build.BuildNumber)
There is relevant documentation here: https://msdn.microsoft.com/en-us/library/vs/alm/build/scripts/variables , which says [sic] 此处有相关文档: https : //msdn.microsoft.com/zh-cn/library/vs/alm/build/scripts/variables ,其内容为[sic]
Any text input can reference a variable by using the $(variable_name) syntax and will be substituted with the actual value at run-time.
任何文本输入都可以使用$(variable_name)语法引用变量,并且在运行时将替换为实际值。 All variables are also exported to the environment as upppercase and any .
所有变量还以upppercase和any形式导出到环境。 are replaced with _.
替换为_。 In scripts you can reference variables via the environment, ie %VARIABLE_NAME%, $VARIABLE_NAME, $env:VARIABLE_NAME, depeding on the operating system.
在脚本中,您可以通过环境引用变量,例如%VARIABLE_NAME%,$ VARIABLE_NAME,$ env:VARIABLE_NAME,具体取决于操作系统。
Based on my trial and error, the first sentence of that paragraph appears true and works if I obey the details from the Global Build Variables section of that documentation when defining the parameters to be provided to my script. 根据我的尝试和错误,如果我在定义要提供给脚本的参数时听从该文档的“全局构建变量”部分的详细信息,则该段落的第一句话会显示为真且有效。 Maybe my use of all-caps and underscores there was deprecated and finally removed in update 2. I think that is issue #1.
也许我对所有大写字母和下划线的使用已被弃用,最后在更新2中删除了。我认为这是问题1。
I have doubts regarding the remaining two sentences about environment variables. 我对关于环境变量的其余两句话有疑问。 When the arguments didn't make it into my script because of issue #1, despite what the documentation says, I saw no evidence of those environment variables.
尽管由于文档#1的原因而使参数由于问题#1未能进入我的脚本,但我看不到任何有关这些环境变量的证据。 This is issue #2, which is what the error messages I first saw were about.
这是问题2,这是我第一次看到的错误消息。 I've changed my script to rely fully on the arguments.
我已更改脚本以完全依赖参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.