Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build.ps1: Imposible to pass an argument value with "," ";" symbols #73

Open
evil-shrike opened this issue Oct 6, 2017 · 6 comments
Open

Comments

@evil-shrike
Copy link

I have a cake script with Argument publishTargets:

var publishTargets = Argument("publishTargets","dev,internal");

I need to pass a value like "dev,internal" or "dev,release" and so on into it.
The key point here is "," symbol. With ";" symbol there's the same picture.

What I tried:

1. via -arg

powershell ./build.ps1 -target Publish -publishTargets="internal,dev" -channel=SNAPSHOT --settings_skipverification=true

Output:

D:\Work\R-n-D\XFW3.git\Build>D:\Work\R-n-D\XFW3.git\Build\build-Publish.cmd
At line:1 char:53
+ ./build.ps1 -target Publish -publishTargets=internal,dev -channel=SNA ...
+                                                     ~
Missing argument in parameter list.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingArgument

2. via ScriptArgs

powershell ./build.ps1 -target Publish -ScriptArgs '-publishTargets="internal,dev" -channel=SNAPSHOT --settings_skipverification=true'

Output:

Running build script...
Invoke-Expression : At line:1 char:158
+ ... n="Release" -verbosity="Verbose"    -publishTargets=internal,dev -cha ...
+                                                                 ~
Missing argument in parameter list.
At D:\Work\R-n-D\XFW3.git\Build\build.ps1:188 char:1
+ Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
    + FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.InvokeExpressionCommand

3. via --arg

powershell ./build.ps1 -target Publish --publishTargets="internal,dev" -channel=SNAPSHOT --settings_skipverification=true

Output:

D:\Work\R-n-D\XFW3.git\Build>D:\Work\R-n-D\XFW3.git\Build\build-Publish.cmd
Preparing to run build script...
Running build script...
More than one build script specified.

Usage: Cake.exe [script] [--verbosity=value]
                [--showdescription] [--dryrun] [..]

Example: Cake.exe

4. Running directly via cake.exe

It works.

tools/Cake/cake -target=Publish -publishTargets="internal;dev" -channel=SNAPSHOT -settings_skipverification=true -verbosity=diagnostic

Environment

Cake 0.22.2
OS x64 Windows 10

@evil-shrike evil-shrike changed the title Imposible to pass an argument value with "," ";" symbols build.ps1: Imposible to pass an argument value with "," ";" symbols Oct 6, 2017
@kcamp
Copy link

kcamp commented Oct 6, 2017

The semicolon is a Powershell literal that you should be able to work around by escaping as such using the backtick ` character. Here is an example that works with Cake 0.21.1

> .\build.ps1 -target Run-Xunit-Tests IncludeTraits='Capability=netcore`;NodeType=Windows'
Tests will be run for: MyAssembly.dll
Including Traits: Capability=netcore;NodeType=Windows                                                                      
Excluding Traits:                                                                          

@evil-shrike
Copy link
Author

@kcamp Thanks! It helps.
This works:

powershell ./build.ps1 -target Publish --publishTargets='internal1`,dev1' -channel=SNAPSHOT --settings_skipverification=true

Only with single quotes (not double).

@kcamp
Copy link

kcamp commented Oct 6, 2017

@evil-shrike Yes, you're correct. I meant to call out the single/double difference because that threw me off, too when I was dealing with the issue. Glad you got it sorted out. 👍

@evil-shrike
Copy link
Author

I think the issue can be closed. But I'm afraid anyone who will try to pass such values (with "," or ";') will encounter difficulties. So ideally (in case it cannot be worked around in the bootstrap ps-script) it should be documented in some way...

@piotrzajac
Copy link

Is it possible to have conditional invocation instead of conditional expression creation with Invoke-Expression? The last one causes real issues in case you want to pass servicePrincipalKey having multiple special characters, when working with Azure CLI. In # Start Cake section, could we have something like:

Write-Host "Running build script..."
if ($IsLinux -or $IsMacOS) {
  &mono $CAKE_EXE $cakeArguments
} else {
  &$CAKE_EXE $cakeArguments
}

Sorry for my code, I'm not a PowerShell expert.

@devlead devlead transferred this issue from cake-build/cake May 22, 2019
@devlead
Copy link
Member

devlead commented May 22, 2019

@piotrzajac probably yes, I think what most do is to pass sectets as environment variables.

Cake repos own bootstrapper does this, it doesn't use Mono though, but instead uses the Cake global tool, so diff between platforms there is executable name
https://github.com/cake-build/cake/blob/06e798370487b61cad711904edf1adf7e772b70f/build.ps1#L148-L153

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

No branches or pull requests

4 participants