Skip to content
This repository has been archived by the owner on Feb 12, 2025. It is now read-only.

The PowerShell task passes list arguments as a single parameter #255

Open
wants to merge 2 commits into
base: release/CCNet-1.8
Choose a base branch
from

Conversation

splatteredbits
Copy link

Steps to reproduce:

Create a PowerShell script:

param(
    [string[]]
    $Path
)

Write-Host $Path.Count

Call this PowerShell script from CCNet. Make sure to pass more than one value to the Path parameter, e.g.

<tasks>
  <powershell>
    <buildArgs>-Path 'string1','string2','string3'</buildArgs>
    <buildTimeoutSeconds>600</buildTimeoutSeconds>
    <scriptsDirectory>F:\Scripts</scriptsDirectory>
    <dynamicValues />
    <environment />
    <executable>powershell.exe</executable>
    <priority>Normal</priority>
    <script>SCRIPT_NAME.ps1</script>
    <successExitCodes />
  </powershell>
</tasks>

The script runs, but the output shows that the number of items passed to the Path parameter is 1, but I expected 3.

This is because CCNet is using PowerShell's -Script parameter instead of -Command. You can replicate this behavior in cmd.exe:

powershell,exe -NoProfile -NonInteractive -File SCRIPT_NAME.ps1 -Path 'string1','string2','string3'

The fix is to use PowerShell's -Command parameter. It interprets everything after it as a full PowerShell command.

@mintsoft
Copy link
Contributor

mintsoft commented May 22, 2017

I have exactly this problem at the moment; no idea why -File was chosen, because it basically doesn't work for anything but simple string inputs!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants