Adding Linux and Windows environment variable support

adam.retter's Avatar

adam.retter

16 May, 2018 07:50 AM

I am trying to add support for Linux builds alongside Windows builds.

Our current AppVeyor.yml for just Windows looks like:

version: '{branch}-{build}'

environment:
  matrix:
    - JAVA_HOME: C:\Program Files\Java\jdk1.8.0
    - JAVA_HOME: C:\Program Files\Java\jdk9

install:
  - cmd: set EXIST_HOME=%APPVEYOR_BUILD_FOLDER%

build_script:
  - cmd: build.bat

test_script:
  - cmd: build.bat -Dexist.autodeploy=off -Dtest.haltonerror=true -Dtest.haltonfailure=true travis

after_test:
  - ps: |
      $wc = New-Object 'System.Net.WebClient'
      foreach ($file in Get-ChildItem -Path "$($env:APPVEYOR_BUILD_FOLDER)\test\junit\data\" -Filter *.xml) {
        $wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $file.FullName)
      }

artifacts:
  - path: test\junit

We need to be able to set different values for environment variables on Windows vs. Linux, I am attempting to use the "for", "only", and "matrix" config options for this but cannot seem to get it to parse correctly. This is what I have so far:

version: '{branch}-{build}'
  
image:
  - Visual Studio 2017
  - Ubuntu

for:
  - matrix:
      only:
        - image: Visual Studio 2017
      environment:
        matrix:
          - JAVA_HOME: C:\Program Files\Java\jdk1.8.0
          - JAVA_HOME: C:\Program Files\Java\jdk9

  - matrix:
      only:
        - image: Ubuntu

install:
  - cmd: set EXIST_HOME=%APPVEYOR_BUILD_FOLDER%
  - sh: export EXIST_HOME=$APPVEYOR_BUILD_FOLDER

build_script:
  - cmd: build.bat
  - sh: build.sh

test_script:
  - cmd: build.bat -Dexist.autodeploy=off -Dtest.haltonerror=true -Dtest.haltonfailure=true travis
  - sh:  build.sh -Dexist.autodeploy=off -Dtest.haltonerror=true -Dtest.haltonfailure=true travis

after_test:
  - ps: |
      $wc = New-Object 'System.Net.WebClient'
      foreach ($file in Get-ChildItem -Path "$($env:APPVEYOR_BUILD_FOLDER)\test\junit\data\" -Filter *.xml) {
        $wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $file.FullName)
      }

artifacts:
  - path: test\junit

How can I get that to generate a matrix of 3 builds which look like:
1. image: Visual Studio 2017 / JAVA_HOME: C:\Program Files\Java\jdk1.8.0
2. image: Visual Studio 2017 / JAVA_HOME: C:\Program Files\Java\jdk9
3. image: Ubuntu

Also I cannot seem to find any information on which versions of Java are available on the Ubuntu image...

  1. Support Staff 1 Posted by Owen McDonnell on 17 May, 2018 03:13 AM

    Owen McDonnell's Avatar

    When it comes to configuring a custom matrix in AppVeyor there are more than one ways to skin a cat (sorry for the gruesome metaphor).

    In your second config example having 'environment.matrix' key nested in 'for' node is not congruent with use case for 'for' node. Rather, the 'for' node modifies an already calculated job matrix.

    But for your particular needs i think you can make use of tweak environment variables and forego the 'image' key.

    environment:
      matrix:
        - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
          JAVA_HOME: C:\Program Files\Java\jdk1.8.0
        - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
          JAVA_HOME: C:\Program Files\Java\jdk9
        - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu
    

    This is alluded to in the docs here.

    By the way, in case you want to actually set the corresponding java folder on your ubuntu build you can find the desired jdk by running ls usr/lib/jvm in yaml. That will give you a listing from which you can choose and then add JAVA_HOME: /usr/lib/jvm/<chosen_jdk> to the ubunut environment matrix group.

  2. 2 Posted by adam.retter on 25 May, 2018 07:54 PM

    adam.retter's Avatar

    Thanks Owen, that has fixed it for me.

  3. adam.retter closed this discussion on 25 May, 2018 07:54 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