使用 PS 环境变量的 TFS 2015 构建步骤失败
TFS 2015 Build Step using PS environment variables fails
我有一个 vNext 构建步骤,它在 MSBuild 之后运行 PowerShell 脚本。我收到此错误:
[error]BUILD_SOURCESDIRECTORY : The term 'BUILD_SOURCESDIRECTORY' 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.
...
[error]BUILD_BUILDNUMBER : The term 'BUILD_BUILDNUMBER' 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.
这是脚本:
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"
剧本已经几周没变了。几个月来构建定义没有改变。 TFS 昨晚更新了更新 1 和 2:
- https://www.visualstudio.com/en-us/news/tfs2015-update1-vs.aspx
- https://www.visualstudio.com/en-us/news/tfs2015-update2-vs.aspx
我尝试进行另一个构建,但它有完全相同的问题,所以这不是第一个煎饼类型的问题。我找不到更新可能对环境变量做了什么以使其无法识别。
如果有任何想法,我将不胜感激,而且我知道如何标记答案! =)
更新:
我尝试删除 TF_,但失败并出现相同的错误
$BuildNumber = $Env:BUILD_BUILDNUMBER
$SolutionRoot = $Env:BUILD_SOURCESDIRECTORY
更新
我们确实让这个再次工作,但我仍然不知道为什么事情会在一夜之间从工作变成不工作。 TFS 更新必须发挥作用。
关于使用 PS 环境变量在更新期间没有任何变化。使用我的 TFS 2015update2 测试通过。
再试以下:
将 $BuildNumber = $Env:TF_BUILD_BUILDNUMBER
更改为 $BuildNumber = $Env:BUILD_BUILDNUMBER
将$SolutionRoot = $Env:TF_BUILD_SOURCESDIRECTORY
更改为$SolutionRoot = $Env:BUILD_SOURCESDIRECTORY
好的,我的构建再次运行,因为我在 TFS 构建定义中调整了如何将参数传递到 PS 脚本。我认为有两个稍微不同的问题在起作用。
以下是 PS 参数字段中对 TFS 2015 Base 起作用的内容:
-SolutionRoot $(BUILD_SOURCESDIRECTORY) -BuildNumber $(BUILD_BUILDNUMBER)
以下是 PS 参数字段中 TFS 2015 Update 2 的工作原理:
-SolutionRoot $(Build.SourcesDirectory) -BuildNumber $(Build.BuildNumber)
这里有相关文档:https://msdn.microsoft.com/en-us/library/vs/alm/build/scripts/variables,上面写着[原文如此]
Any text input can reference a variable by using the $(variable_name) syntax and will be substituted with the actual value at run-time. All variables are also exported to the environment as upppercase and any . are replaced with _. In scripts you can reference variables via the environment, i.e. %VARIABLE_NAME%, $VARIABLE_NAME, $env:VARIABLE_NAME, depeding on the operating system.
根据我的反复试验,如果我在定义要提供给我的脚本的参数时遵守该文档的“全局构建变量”部分的详细信息,那么该段的第一句话似乎是正确的并且有效。也许我对全大写和下划线的使用在更新 2 中被弃用并最终被删除。我认为这是问题 #1。
我对剩下的两句环境变量有疑惑。当参数由于问题 #1 而没有进入我的脚本时,无论文档怎么说,我都没有看到这些环境变量的证据。这是问题 #2,这是我第一次看到的错误消息的内容。我已更改我的脚本以完全依赖参数。
我有一个 vNext 构建步骤,它在 MSBuild 之后运行 PowerShell 脚本。我收到此错误:
[error]BUILD_SOURCESDIRECTORY : The term 'BUILD_SOURCESDIRECTORY' 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.
...
[error]BUILD_BUILDNUMBER : The term 'BUILD_BUILDNUMBER' 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.
这是脚本:
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"
剧本已经几周没变了。几个月来构建定义没有改变。 TFS 昨晚更新了更新 1 和 2:
- https://www.visualstudio.com/en-us/news/tfs2015-update1-vs.aspx
- https://www.visualstudio.com/en-us/news/tfs2015-update2-vs.aspx
我尝试进行另一个构建,但它有完全相同的问题,所以这不是第一个煎饼类型的问题。我找不到更新可能对环境变量做了什么以使其无法识别。
如果有任何想法,我将不胜感激,而且我知道如何标记答案! =)
更新: 我尝试删除 TF_,但失败并出现相同的错误
$BuildNumber = $Env:BUILD_BUILDNUMBER
$SolutionRoot = $Env:BUILD_SOURCESDIRECTORY
更新 我们确实让这个再次工作,但我仍然不知道为什么事情会在一夜之间从工作变成不工作。 TFS 更新必须发挥作用。
关于使用 PS 环境变量在更新期间没有任何变化。使用我的 TFS 2015update2 测试通过。
再试以下:
将 $BuildNumber = $Env:TF_BUILD_BUILDNUMBER
更改为 $BuildNumber = $Env:BUILD_BUILDNUMBER
将$SolutionRoot = $Env:TF_BUILD_SOURCESDIRECTORY
更改为$SolutionRoot = $Env:BUILD_SOURCESDIRECTORY
好的,我的构建再次运行,因为我在 TFS 构建定义中调整了如何将参数传递到 PS 脚本。我认为有两个稍微不同的问题在起作用。
以下是 PS 参数字段中对 TFS 2015 Base 起作用的内容:
-SolutionRoot $(BUILD_SOURCESDIRECTORY) -BuildNumber $(BUILD_BUILDNUMBER)
以下是 PS 参数字段中 TFS 2015 Update 2 的工作原理:
-SolutionRoot $(Build.SourcesDirectory) -BuildNumber $(Build.BuildNumber)
这里有相关文档:https://msdn.microsoft.com/en-us/library/vs/alm/build/scripts/variables,上面写着[原文如此]
Any text input can reference a variable by using the $(variable_name) syntax and will be substituted with the actual value at run-time. All variables are also exported to the environment as upppercase and any . are replaced with _. In scripts you can reference variables via the environment, i.e. %VARIABLE_NAME%, $VARIABLE_NAME, $env:VARIABLE_NAME, depeding on the operating system.
根据我的反复试验,如果我在定义要提供给我的脚本的参数时遵守该文档的“全局构建变量”部分的详细信息,那么该段的第一句话似乎是正确的并且有效。也许我对全大写和下划线的使用在更新 2 中被弃用并最终被删除。我认为这是问题 #1。
我对剩下的两句环境变量有疑惑。当参数由于问题 #1 而没有进入我的脚本时,无论文档怎么说,我都没有看到这些环境变量的证据。这是问题 #2,这是我第一次看到的错误消息的内容。我已更改我的脚本以完全依赖参数。