Separate cache statements per operating system?

Justin Grote's Avatar

Justin Grote

05 Dec, 2018 03:25 PM

This is sort of a cosmetic thing, but I'd like to split the cache statements in my appveyor.yml to only apply depending on Linux or Windows. Is there any way to use the for: or on: statements to filter to an image? I know how to do it by branch, but wanted to do it by image, as some are not applicable.

Also, is there an environment variable format that I can use cross-platform? %USERPROFILE% doesn't resolve on Ubuntu

Example:
cache:
  - '%USERPROFILE%\Documents\WindowsPowerShell\Modules -> PSModule.requirements.ps1'
  - '%USERPROFILE%\Documents\PowerShell\Modules -> PSModule.requirements.ps1'
  - '%LOCALAPPDATA%\PackageManagement\NuGet'
  - '/home/appveyor/.dotnet'
  - '/home/appveyor/.nuget'
  - '/home/appveyor/.cache/powershell'
  - '/home/appveyor/.local/share/NuGet'
  - '/home/appveyor/.local/share/powershell'
  - '/home/appveyor/.config/share/powershell'

  1. Support Staff 1 Posted by Owen McDonnell on 05 Dec, 2018 04:07 PM

    Owen McDonnell's Avatar

    Sure, this is described here with the following as an example.

    image:
    - Visual Studio 2017
    - Ubuntu
    build:
      project: src
      publish_wap: true
      verbosity: minimal
    
    for:
    -
      matrix:
        only:
          - image: Ubuntu
      cache: 
        -/home/appveyor/.nuget
    
  2. 2 Posted by Justin Grote on 05 Dec, 2018 09:03 PM

    Justin Grote's Avatar

    OK I didn't realize for: was that flexible based on the example. Thanks!

  3. 3 Posted by Justin Grote on 05 Dec, 2018 09:33 PM

    Justin Grote's Avatar

    I tried this and it worked if I only specify one matrix: statement. However, when I try the second matrix statement for the Windows (for windows only tasks) the Appveyor YAML Validator fails saying 'Invalid "matrix" setting: cache (Line: 49, Column: 5)'

    Am I doing the syntax right? It validated as valid YAML otherwise (attached). I tried simplifying it down to just cache and same result.

  4. 4 Posted by Justin Grote on 05 Dec, 2018 09:49 PM

    Justin Grote's Avatar

    Nevermind I figured it out, my indents were a little off. Here's the
    finished .yml for posterity for future searchers.

    # See http://www.appveyor.com/docs/appveyor-yml for many more options
    version: '{build}-{branch}'

    image:
    - Visual Studio 2017
    - Ubuntu

    #Encrypted Variables - https://ci.appveyor.com/tools/encrypt
    environment:
    GitHubUserName: JustinGrote
    GitHubAPIKey:
    secure: MolSn4T0aNBnph/BVkKA8HQ1qvpJjIV3CcjRg3DYynijlOVL5RftqbXD5l0IUw6L
    NuGetAPIKey:
    secure: HncD30pn+cWRepdP28pyB1l4BNg3x3MdvcNV8EysOhQ5kBFMHVyXiQM0whuUW78P
    APPVEYOR_SSH_KEY: ssh-rsa
    AAAAB3NzaC1yc2EAAAABJQAAAQEAqOJfFgHyHbQk1d/oCxPn2mGCd92GOFaT9PvA4pICCpMH8w+9Cv1OZpNcwvk+RIzTO9Fm8ilfK/x4gUFrRmAp9BkkmFDhqol0/3e2ZrsxjsYJsUcic/fcRINrDTrwSMaOghUO2fcSTJ3N7WsGKlcG3NXszPgJD95Ulpgk6qvclWJEt15xoYuqHnlhohkXA3zbfcWzuGsMZkuv1fMZB5nEjfLKegzCesQ+swAUaEbUxOeKIFD4VlluDuKONeKqDTETkpLZXKV8pRwDBxgD3i8zQJcSGZ8XoYyPLPbZD/J7AEOap6uYOr4jC8EbFug8SsnxPQ7vxnwslgHoRFzNeYlkIQ==
    d8:72:f4:1f:1f:31:4c:01:ce:3e:5a:ec:1b:31:8b:da rsa-jgrote-Jan2016

    # Skip on updates to the readme.
    # We can force this by adding [skip ci] or [ci skip] anywhere in commit
    message
    skip_commits:
    message: /updated README.*|Update README.*s/

    # Skip Tags with GitHub
    # Releases are tracked and tagged by the build script in Appveyor, having
    this enabled results in a double build
    skip_tags: true

    #Kick off the CI/CD pipeline. We do test and build in the same script
    #To be portable to non-Appveyor builds
    build_script:
    - ps: .\build.ps1

    #Capture the artifacts
    artifacts:
    - path: Release\*.zip
    name: Powershell Module Zip Package

    - path: Release\*.nupkg
    name: Powershell Module NuGet Package

    #Save the following files for faster subsequent builds
    for:
    - matrix:
    only:
    - image: Ubuntu
    init:
    - ps: if ($isLinux -and ($env:APPVEYOR_REPO_COMMIT_MESSAGE -match
    'AppveyorSSHDebug')) {"export APPVEYOR_SSH_BLOCK=true" +
    [Environment]::NewLine + (iwr -useb '
    https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh').content
    | bash -e -}
    cache:
    - '/home/appveyor/.nuget'
    - '/home/appveyor/.cache/powershell'
    - '/home/appveyor/.local/share/NuGet'
    - '/home/appveyor/.local/share/powershell'
    - '/home/appveyor/.config/share/powershell'
    on_finish:
    - ps: if ($isLinux -and ($env:APPVEYOR_REPO_COMMIT_MESSAGE -match
    'AppveyorSSHDebug')) {"export APPVEYOR_SSH_BLOCK=true" +
    [Environment]::NewLine + (iwr -useb '
    https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh').content
    | bash -e -}

    - matrix:
    only:
    - image: Visual Studio 2017
    init:
    - ps: if ($isWindows -and ($env:APPVEYOR_REPO_COMMIT_MESSAGE -match
    'AppveyorRDPDebug')) {$blockRdp = $true; iex (iwr -useb '
    https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1').content
    }
    cache:
    - '%USERPROFILE%\Documents\WindowsPowerShell\Modules ->
    PSModule.requirements.ps1'
    - '%USERPROFILE%\Documents\PowerShell\Modules -> PSModule.requirements.ps1'
    - '%LOCALAPPDATA%\PackageManagement\NuGet'
    deploy_script:
    - ps: .\build.ps1 Publish
    on_finish:
    - ps: if ($isWindows -and ($env:APPVEYOR_REPO_COMMIT_MESSAGE -match
    'AppveyorRDPDebug')) {$blockRdp = $true; iex (iwr -useb '
    https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1').content
    }

  5. 5 Posted by Justin Grote on 05 Dec, 2018 09:50 PM

    Justin Grote's Avatar

    Err, that formatting didn't come out as expected. Attached.

  6. Support Staff 6 Posted by Owen McDonnell on 05 Dec, 2018 11:33 PM

    Owen McDonnell's Avatar

    Cool, thanks for your contribution to posterity!

  7. Owen McDonnell closed this discussion on 05 Dec, 2018 11: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

 

26 Sep, 2024 03:49 PM
26 Sep, 2024 09:02 AM
25 Sep, 2024 07:07 PM
24 Sep, 2024 08:39 PM
24 Sep, 2024 06:47 AM
20 Sep, 2024 05:50 PM