简体   繁体   English

在自定义TFS构建/发布脚本中获取DistributedTaskContext

[英]Obtaining the DistributedTaskContext in a custom TFS Build/Release Script

I'm using TFS 2015 Update 2 along with the new Build/Release system. 我正在使用TFS 2015 Update 2和新的“构建/发布”系统。 I have a powershell script I'm executing via the Powershell Task. 我有一个通过Powershell任务执行的powershell脚本。 This task executes a powershell script that needs access to the $distributedExecutionContext magic variable I see in many different VSTS Task code samples. 该任务执行一个Powershell脚本,该脚本需要访问$ distributedExecutionContext魔术变量,我在许多不同的VSTS Task代码示例中都看到了该变量。

This script in question is not technically a task, but instead is being executed by the Powershell task that comes delivered with TFS. 从技术上讲,该脚本不是任务,而是由TFS随附的Powershell任务执行。

No matter what I do, I can't see to obtain the $distributedExecutionContext variable. 无论我做什么,我都看不到获得$ distributedExecutionContext变量。 It's always null. 它始终为空。 Here is an example: 这是一个例子:

Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"

if($distributedTaskContext)
{
    #... this never happens
}

Is this variable only available if the powershell being run is being run inside an actual task? 仅当正在运行的Powershell在实际任务中运行时,此变量才可用吗?

The default powershell task that you are using runs the script entirely as a different process and the $distributedTaskContext variable is not available to the script. 您使用的默认Powershell任务将脚本完全作为另一个进程运行,并且$distributedTaskContext变量不可用于该脚本。

It is only available only to the task's powershell script. 它仅适用于任务的powershell脚本。

If you are going to write a custom task, I would like you to use the new vsts-task-lib SDK which improves a lot over old SDK. 如果您要编写自定义任务,我希望您使用新的vsts-task-lib SDK ,它比旧的SDK有很多改进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM