1
votes

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.

Problem: I can't get that array from PowerShell fed back to the team build. 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.

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).

They key bit is that tool I have to send this array through needs to consist of strings.

2

2 Answers

1
votes

If it were me I'd just loop through and call your custom tool directly from PowerShell, rather than trying to pass data back to WF and doing it from there.

0
votes

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...

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.