简体   繁体   English

将PowerShell数组传递回TFS构建模板

[英]Passing a PowerShell Array back to TFS build Template

I pieced together a pipeline that returns a list of files and their paths if said files match prescribed patterns: 我拼凑了一个管道,如果所述文件与指定的模式匹配,则该管道返回文件及其路径的列表:

Param ($dropDir)

$MatchingScripts = Get-ChildItem $dropDir\*.sql -Recurse 
    | Select-String -pattern \*ONEFISH\*,\*TWOFISH\*,\*REDFISH\* 
    | group path 
    | Foreach-Object {$_.Name} 
    | Out-File D:\logging\scrubfiles.log

return $MatchingScripts

So there's one param in there where I feed in the dynamically-named drop path every time and search down that path. 因此,这里有一个参数,我每次都会输入动态命名的放置路径并向下搜索该路径。 The goal then is to return $MatchingScripts array to the build template and throw the array into a ForEach<string> loop that will InvokeProcess on a custom tool which will scrub each \\path\\file\\ and replace said token value patterns. 然后,目标是将$MatchingScripts数组返回到构建模板,并将该数组放入ForEach<string>循环中,该循环将在定制工具上调用InvokeProcess,该定制工具将清理每个\\ path \\ file \\并替换所述标记值模式。

Problem: I can't get that array from PowerShell fed back to the team build. 问题:我无法从PowerShell中将该阵列反馈给团队构建。 I've tried containing the script in a .ps1 along with a closing return $MatchingScripts ...but nothing is reaching the pre-defined IEnumerable<String> by the same name 'MatchingScripts' in the build template. 我试过将脚本与结束return $MatchingScripts一起包含在.ps1中...但是在构建模板中没有任何东西以相同的名称“ MatchingScripts”到达预定义的IEnumerable<String>

I'm still trying to make the TFSBuildExtensions InvokePowerShellCommand activity to do this for me, as well, but the problem there is a conversion of types that have to be overcome (PSOBject to Array of Strings). 我仍在尝试通过TFSBuildExtensions InvokePowerShellCommand活动来为我执行此操作,但是问题是必须克服类型转换(PSOBject到字符串数组)的问题。

They key bit is that tool I have to send this array through needs to consist of strings. 他们的关键是我必须通过包含字符串的数组来发送此数组的工具。

如果是我,我将循环浏览并直接从PowerShell调用您的自定义工具,而不是尝试将数据传递回WF并从那里进行操作。

Here's the work-around we used to return value: 这是我们用来返回值的解决方法:

Since what we piped out to log was clean (just files & paths), we read the log back into an array of strings via the Assign activity using a VB expression... 由于我们传递到日志的内容是干净的(只是文件和路径),因此我们使用VB表达式通过Assign活动将日志读回到字符串数组中。

MatchingScripts = File.ReadAllLines("D:\logging\scrubfiles_" + BuildDetail.BuildNumber.ToString() + ".txt")

There's a little concatenation there because we later chose to individualize the each log according to the 'build' it ran under. 那里有一点串联,因为我们后来选择根据运行的“构建”来个性化每个日志。 Anyway, it worked a treat! 无论如何,它确实起到了治疗作用!

Moral of the story: understand that if you want to return ANYTHING other than an integer value from PowerShell/InvokeProcess, be prepared to write/find a custom activity or come up with some other work-around that can feed directly back into Workflow. 故事的寓意:了解如果您想从PowerShell / InvokeProcess返回除整数值以外的任何内容,请准备编写/查找自定义活动,或者提出一些其他解决方法,这些解决方法可以直接反馈到Workflow中。

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

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