5

I am trying to execute following test.ps1 script

param([string]$name,[string]$password);
write-Output "Hello $($name) my password is  $($password)";
dir c:\
New-Item c:\HRTemp\test.txt -ItemType file

on remote server using following command

StartPowershellScript("Invoke-Command", args =>
{
    args.Append("ScriptBlock", "{{c:\\test.ps1 -name dato -password test}}" );
});

I was able to successfully invoke this command from command line and now I want the same using cake script.

I am using Cake.Powershell addin.

When I try to execute it with one curly brace {c:\\test.ps1 -name dato -password test} , I am getting error:

Error: Input string was not in a correct format.

When I try it with two curly brace

{{c:\\test.ps1 -name dato -password test}}

output is the following

Executing: Invoke-Command -ScriptBlock {{c:\test.ps1 -name dato -password test}}

but, when I check on remote server test.txt file is not created.

Do you have any ideas why this is happening?

bumbeishvili
  • 1,342
  • 14
  • 27

1 Answers1

3

This is caused by the different handling of curly braces by the ProcessArgumentBuilder used internally by the Cake.Powershell addin, and the format parser used internally in Cake's internal logger.

I submitted a PR to Cake.Powershell which has now been merged and a new release published, so upgrading to version 0.2.7 will resolve this issue for you.

You should then be able to use something like the following:

StartPowershellScript("Invoke-Command", args =>
{
    args.Append("hostname").Append("-ScriptBlock {c:\\test.ps1 -name dato - password test}");
});

And while the log will include double braces, the actual command will only use single braces and should run correctly.

agc93
  • 663
  • 1
  • 7
  • 19
  • now I am getting Error: C:/BuildAgent/work/f4bd1e7f8392f527/TeamCityTest/Cake/build.cake(128,1): error CS8000: This language feature ('Label in interactive') is not yet implemented in Roslyn. – bumbeishvili Oct 05 '16 at 07:45
  • 1
    Okay I think that must be a different issue. Check [this repo](https://github.com/agc93/cake-ps-sample) for a sample of what I described working fine, so at least the brackets part is fixed. – agc93 Oct 05 '16 at 13:44