Search code examples
windowspowershellcontinuous-integrationappveyor

Why can't PowerShell match $env:image in AppVeyor?


I'm trying to integrate CMake builds into AppVeyor. Our project is Visual Studio based for Windows, but we try to support CMake for users who prefer it.

Our .appveyor.yml script is shown below (and available online). The problem is, PowerShell does not match $env:image and eventually the else is executed. The else is a MSBuild path, and not a CMake path.

The result is shown in the image (and available online). In the image below, notice the Visual Studio, MSBuild on line 107. That's echo'd from the script.

enter image description here

I also checked-in a try with $image -eq "Visual Studio 2017", too. But still no match.

I could be doing something awfully wrong. I'm not an AppVeyor expert, and today is my first day of PowerShell scripting (though I have scripting experience in other environments).

Why can't PowerShell match $env:image in AppVeyor?


# Appveyor's documentation is at https://www.appveyor.com/docs/build-phase/,
#  and a sample configuration file is at https://www.appveyor.com/docs/appveyor-yml/.
#  I have to admit its a bit complex and I don't fully understand it.

version: 1.0.{build}
clone_depth: 3
skip_tags: true

configuration:

- Debug
- Release

platform:

- Win32
- x64

image:

- Visual Studio 2017
- Visual Studio 2015
- Visual Studio 2013

environment:

  matrix:

  - BUILD_MODE: CMake
  - BUILD_MODE: MSBuild

# Disable build through solution file
build: off

# Build through commands in script below
test_script:

- ps: >-

    if($env:image -eq "Visual Studio 2017" -and $env:BUILD_MODE -eq "CMake")
    {

        echo "Visual Studio 2017, CMake"

        mkdir cmake-build

        cd cmake-build

        if($env:configuration -eq "Debug")
        {

            cmake -G "Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=Debug ../

        }
        else
        {

            cmake -G "Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=Release ../

        }

        msbuild /t:Build cryptopp-static.vcxproj

        msbuild /t:Build cryptopp.vcxproj

        .\cryptest.exe v

        .\cryptest.exe tv all

    }
    elseif($env:image -eq "Visual Studio 2015" -and $env:BUILD_MODE -eq "CMake")
    {

        echo "Visual Studio 2015, CMake"

        mkdir cmake-build

        cd cmake-build

        if($env:configuration -eq "Debug")
        {

            cmake -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE=Debug ../

        }
        else
        {

            cmake -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE=Release ../

        }

        msbuild /t:Build cryptopp-static.vcxproj

        msbuild /t:Build cryptopp.vcxproj

        .\cryptest.exe v

        .\cryptest.exe tv all

    }
    elseif($env:image -eq "Visual Studio 2013" -and $env:BUILD_MODE -eq "CMake")
    {

        echo "Visual Studio 2013, CMake"

        mkdir cmake-build

        cd cmake-build

        if($env:configuration -eq "Debug")
        {

            cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Debug ../

        }
        else
        {

            cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Release ../

        }

        msbuild /t:Build cryptopp-static.vcxproj

        msbuild /t:Build cryptopp.vcxproj

        .\cryptest.exe v

        .\cryptest.exe tv all

    }
    else
    {

        echo "Visual Studio, MSBuild"

        msbuild /t:Build /p:platform="$env:platform" /p:configuration="$env:configuration" cryptlib.vcxproj

        msbuild /t:Build /p:platform="$env:platform" /p:configuration="$env:configuration" cryptest.vcxproj

        msbuild /t:CopyCryptestToRoot cryptest.vcxproj

        .\cryptest.exe v

        .\cryptest.exe tv all

    }

notifications:
  - provider: Email
    to:
      - cryptopp-build@googlegroups.com
    on_build_success: true
    on_build_failure: true

Solution

  • image is not environment variable, but only YAML tag, which understood by AppVeyor. List of environment variables are here: https://www.appveyor.com/docs/environment-variables/.

    What you are looking for is APPVEYOR_BUILD_WORKER_IMAGE. Note that this variable is "double edged". You can use it just to display current image, but also you can use it to set image in build matrix (it is useful when you have tricky combinations of images and other variables).