Multiple line cmd in appveyor.yml

william's Avatar

william

19 Mar, 2015 05:42 PM

I get errors using multiple line commands. How do I put something like the following into appveyor.yml:

install:
  - if "%Platform%" == "x86" (
      set PCRE_PLATFORM=Win32
      set JAVA_HOME=c:/Program Files (x86)/Java/jdk1.8.0
      set VCVARS_PLATFORM=x86
      set LANG_PLATFORM=
    ) else (
      set PCRE_PLATFORM=x64
      set JAVA_HOME=c:/Program Files/Java/jdk1.8.0
      set VCVARS_PLATFORM=amd64
      set LANG_PLATFORM=-x64
    )

  1. Support Staff 1 Posted by Feodor Fitsner on 19 Mar, 2015 08:44 PM

    Feodor Fitsner's Avatar

    Hi William,

    Put this script on UI and then use "Export YAML" feature on project settings to get appveyor.yml equivalent.

  2. 2 Posted by william on 20 Mar, 2015 09:30 PM

    william's Avatar

    I'm not having much luck. First I corrected the escaping of (x86) to use ^(x86^), but the UI suggests I use:

    if "%Platform%" == "x86" (
    ' set PCRE_PLATFORM=Win32'
    ' set JAVA_HOME=c:/Program Files (x86)/Java/jdk1.8.0'
    ' set VCVARS_PLATFORM=x86'
    ' set LANG_PLATFORM='
    ) else (
    ' set PCRE_PLATFORM=x64'
    ' set JAVA_HOME=c:/Program Files/Java/jdk1.8.0'
    ' set VCVARS_PLATFORM=amd64'
    ' set LANG_PLATFORM=-x64'
    )

    which also gives an error. I converted this to powershell next and the UI suggested:

      - ps: >-
        If ($env:Platform -Match "x86") {
              $env:PCRE_PLATFORM="Win32"
              $env:JAVA_HOME="c:/Program Files (x86)/Java/jdk1.8.0"
              $env:VCVARS_PLATFORM="x86"
              $env:LANG_PLATFORM=""
        } Else {
              $env:PCRE_PLATFORM="x64"
              $env:JAVA_HOME="c:/Program Files/Java/jdk1.8.0"
              $env:VCVARS_PLATFORM="amd64"
              $env:LANG_PLATFORM="-x64"
        }

    This gives an error:

    Error parsing appveyor.yml: (Line: 46, Col: 5, Idx: 1195) - (Line: 46, Col: 5, Idx: 1195): While scanning a simple key, could not find expected ':'.

    Does the : in $env:XXX have to escaped or something? Seems like there is a bug here somewhere in either parsing appveyor.yml or the UI's generator/converter of the scripts.

  3. Support Staff 3 Posted by Feodor Fitsner on 21 Mar, 2015 05:03 AM

    Feodor Fitsner's Avatar

    "Export YAML" suggested the following:

    install:
    - ps: "If ($env:Platform -Match \"x86\") {\n  $env:PCRE_PLATFORM=\"Win32\"\n  $env:JAVA_HOME=\"c:/Program Files (x86)/Java/jdk1.8.0\"\n  $env:VCVARS_PLATFORM=\"x86\"\n  $env:LANG_PLATFORM=\"\" \n} Else {\n  $env:PCRE_PLATFORM=\"x64\"\n  $env:JAVA_HOME=\"c:/Program Files/Java/jdk1.8.0\"\n  $env:VCVARS_PLATFORM=\"amd64\"\n  $env:LANG_PLATFORM=\"-x64\" \n}"
    

    It's weird indeed. Maybe it's better put that into separate .ps1 file?

  4. Support Staff 4 Posted by Feodor Fitsner on 21 Mar, 2015 05:05 AM

    Feodor Fitsner's Avatar

    No, seems like there were some special symbols at line endings. After cleaning up the script it gives:

    install:
    - ps: >-
        If ($env:Platform -Match "x86") {
          $env:PCRE_PLATFORM="Win32"
          $env:JAVA_HOME="c:/Program Files (x86)/Java/jdk1.8.0"
          $env:VCVARS_PLATFORM="x86"
          $env:LANG_PLATFORM=""
        } Else {
          $env:PCRE_PLATFORM="x64"
          $env:JAVA_HOME="c:/Program Files/Java/jdk1.8.0"
          $env:VCVARS_PLATFORM="amd64"
          $env:LANG_PLATFORM="-x64"
        }
    
  5. Support Staff 5 Posted by Feodor Fitsner on 21 Mar, 2015 05:08 AM

    Feodor Fitsner's Avatar

    Oh, found it. Apparently, if there is a space character at the end of a line it breaks formatting and gives single quoted line.

  6. 6 Posted by william on 24 Mar, 2015 08:06 AM

    william's Avatar

    The file was in Unix format, so used \n instead of \r\n, probably the copy/paste used the unix line ending. Perhaps the UI should be enhanced to deal with this common line ending as well as trailing spaces? Anyway, the powershell multiline 'if' statement works now, and I gave up with the cmd multiline 'if' statement. Thanks for your help.

  7. william closed this discussion on 26 Mar, 2015 07:33 PM.

Comments are currently closed for this discussion. You can start a new one.

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