Skip to content

Fake.Tools.Octo creates invalid command line args #2464

Closed

Description

@CiaranMacCarthaigh

Description

On Windows, when using Fake.Tools.Octo to push a package to Octopus, the command line arguments are not correctly constructed, causing Octopus to fail.

Repro steps

  1. Ensure that you have dotnet-octo.exe in a valid path.

  2. Call Fake.Tools.Octo.push with one package. An example is shown:

let setCommon (ps:Octo.Options) =
     { ps with ToolPath = @".octo\"  // Replace this with the correct path to the folder containing dotnet-octo.exe
               ToolName = "dotnet-octo.exe"
               Server = {
               ServerUrl = "octopusServer"
               ApiKey = "ABC123456" }
     }

Octo.push (fun options ->
    { options with
        Common = setCommon options.Common
        Packages = [ "valid-file-path" ]
    }
)

Expected behavior

Octopus correctly parses the command line options.

Actual behavior

Octopus cannot parse the command line options and returns an error:

Unrecognized command arguments: --package=valid-file-path

Related information

  • Operating system: Windows 10.0.18363.628
  • Branch: release/next
  • Runtime: .NET Core 3.1
  • Severity: major
  • Version of FAKE: 5.19 (Fake.Tools.Octo version: 5.19.0)

Known workarounds

This issue does not appear in certain earlier versions of Fake.Tools.Octo (such as 5.12). I don't know which versions are affected, I haven't tried to reproduce them.

Probable cause and possible solution

From what I've read of the code, what happens is roughly:

  1. Octo takes the packages and converts the collection into a string of the format:
    --package=valid-file-path. Each of them are separated by a space character. This is done in the function stringListParam. However, it also adds a space character before the first item. Unless the collection is empty, the first character in the resultant string is always a space.

  2. Eventually, when preparing the command line to start the process, CmdLineParsing.windowsArgvToCommandLine will iterate through the arguments provided. Because this packages argument has a space as the first character, it wraps it in double quotations, to account for the space. The string it creates is then:

push " --package=valid-file-path" --server=octopusServer --apikey=ABC123456

which is invalid for Octopus.

If the string returned by stringListParam does not have this starting space then windowsArgvToCommandLine will return:

push --package=valid-file-path --server=octopusServer --apikey=ABC123456

which is valid for Octopus.

A possible solution is to Trim the string that comes out of stringListParam, to remove leading whitespace. This will only patch over the problem, for one package. Supplying more than one package will result in a command line like:

push "--package=valid-file-path-1 --package=valid-file-path-2 --package=valid-file-path-3" --server=octopusServer --apikey=ABC123456

which is also invalid.

Activity

  1. github-actions commented on Feb 6, 2020

    @github-actions
    Contributor

    Welcome to the FAKE community! Thank you so much for creating your first issue and therefore improving the project!

  2. matthid commented on Feb 9, 2020

    @matthid
    Member

    Yes indeed, thanks for the analysis! That module needs some updates, it needs to use the latest arguments parsing APIs so things like this cannot happen anymore.
    I hope someone can send a PR :)

  3. CiaranMacCarthaigh commented on Feb 11, 2020

    @CiaranMacCarthaigh
    Author
  4. matthid commented on Feb 11, 2020

    @matthid
    Member
  5. CiaranMacCarthaigh commented on Feb 11, 2020

    @CiaranMacCarthaigh
    Author

    I'll have a crack at it.

  6. ids-pfinn commented on Feb 12, 2020

    @ids-pfinn
    Contributor

    @CiaranMacCarthaigh Pretty sure this was due to my PR and I think I fixed it here it is only a quick fix instead of porting tot he new arguments module. Sorry you ran into the bug!

  7. matthid commented on May 7, 2020

    @matthid
    Member

    I guess this has been solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions