为什么 PowerShell 无法匹配 AppVeyor 中的 $env:image?

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

我正在尝试将 CMake 构建集成到 AppVeyor 中。我们的项目 Visual Studio 基于 Windows,但我们尝试为喜欢它的用户支持 CMake。

我们的 .appveyor.yml 脚本如下所示(和 available online)。问题是,PowerShell 不匹配 $env:image,最终 else 被执行。 else 是 MSBuild 路径,而不是 CMake 路径。

结果如图所示(和available online)。在下图中,请注意第 107 行的 Visual Studio, MSBuild。这是从脚本中回显的。

我也尝试了 $image -eq "Visual Studio 2017"。但是仍然没有匹配。

我可能做错了什么。我不是 AppVeyor 专家,今天是我第一天使用 PowerShell 脚本(尽管我有其他环境的脚本经验)。

为什么 PowerShell 无法匹配 AppVeyor 中的 $env:image


# 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

image不是环境变量,只是AppVeyor理解的YAML标签。环境变量列表在这里:https://www.appveyor.com/docs/environment-variables/

您要找的是APPVEYOR_BUILD_WORKER_IMAGE。注意这个变量是"double edged"。您可以仅使用它来显示当前图像,也可以将它用于 set image in build matrix(当您对图像和其他变量进行巧妙组合时它很有用)。