Multi line cmd or powershell warning ignore ?

xarkes's Avatar

xarkes

12 May, 2017 08:33 AM

Hi,
I have a project with different jobs, and for more readability, I want to cut my 1000chars + lines into multiple lines.
So here is what I came to :

build_script:
  - ps: >-
      If ($env:platform -Match "msvc") {
        & msvc.bat
      } ElseIf ($env:platform -Match "mingw32") {
        $env:PATH = "xxx;$env:PATH"
        cmd1
        cmd2
        ...
        cmd99
      }

The problem is that when any of my command generate a warning on stderr (which happens often in a Debug build, and which is not always threatening the project health state), the build fails -- I found out that it is because of powershell receiving something on its stderr.
Now, one of the answer I found on this forum is to "use cmd". Ok so let's translate my code like this:

build_script:
  - cmd: >-
      if %platform% == msvc )
        msvc.bat
      ) else (
        set PATH = "xxx;%PATH%"
        cmd1
        cmd2
        ...
        cmd99
      )
But no, it just does not work, because (apparently) the cmd command does not support the if statement over multiple lines. It's multi line, but still one line at a time.
Of course, the working way would be to have something like this:
build_script:
  - cmd: if %platform% == msvc ( msvc.bat ) else ( cmd1 && cmd2 && cmd3 && cmd4 && cmd5 && cmd6 && cmd7 && cmd8 && cmd9 && cmd10 && cmd11 && cmd12 && cmd13 && cmd14 && cmd15 && cmd16 && cmd17 && cmd18 && cmd19 && cmd20 && cmd 21 && cmd 22 && cmd 23 && cmd 24 && ... && cmd99 )
This is so dirty and so hard to maintain that I do hope any of you have a good alternative to solve my problem ! (either ignore warnings with powershell, or use multiple lines with the cmd directive.
I hope my problem is clear enough, and thank you in advance
  1. Support Staff 1 Posted by Ilya Finkelshte... on 12 May, 2017 01:10 PM

    Ilya Finkelshteyn's Avatar

    You can use tweak/hack from our previous conversation like this:

    environment:
      matrix:
      - platform: msvc
        build_command: msvc.bat
      - platform: cygwin32
        build_command: cygwin32.bat
    build_script:
    - cmd: '%build_command%
    
    and keep all multi-line script in .bat files instead of YAML... Also no need to if/else with this approach.
  2. 2 Posted by xarkes on 12 May, 2017 02:48 PM

    xarkes's Avatar

    Could you please paste an example with multiple commands ?
    From what you show me, I think that I will have something like this in the end.

    environment:
      matrix:
        - platform: msvc
          build_command: "msvc.bat"
        - platform: cygwin32
          build_command: "cmd1 && cmd2 && cmd3 && cmd4 && cmd5 && cmd6 && cmd7 && cmd8 && cmd9 && cmd10 && cmd11 && cmd12 && cmd13 && cmd14 && cmd15 && cmd16 && cmd17 && cmd18 && cmd19 && cmd20 && cmd 21 && cmd 22 && cmd 23 && cmd 24 && ... && cmd99"
    
    Which does not really do what I wanted in a first place ?
  3. Support Staff 3 Posted by Feodor Fitsner on 12 May, 2017 05:48 PM

    Feodor Fitsner's Avatar

    Ilya meant you have to put your commands to a separate my_build_commands.cmd file, commit that my_build_commands.cmd file into repository and then use from appveyor.yml:

    ...
    build_script:
    - my_build_commands.cmd
    
  4. 4 Posted by xarkes on 12 May, 2017 06:03 PM

    xarkes's Avatar

    Ok that's what I was thinking, thanks for precising :)

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac