Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github actions: set environment variable for Windows build with PowerShell

I define GENERATOR_PLATFORM as an empty environment variable, and then I want to set it to something for my Windows build. But, the variable never gets set:

env:
  GENERATOR_PLATFORM:

 steps:
    - name: windows-dependencies
      if: startsWith(matrix.os, 'windows')
      run: |
         $generator= "-DCMAKE_GENERATOR_PLATFORM=x64"
        echo "Generator: ${generator}"
        echo "GENERATOR_PLATFORM=$generator" >> $GITHUB_ENV

   - name: Configure CMake
      shell: bash
      working-directory: ${{github.workspace}}/build
      run: cmake $GITHUB_WORKSPACE $GENERATOR_PLATFORM
like image 813
Jacko Avatar asked Dec 31 '22 15:12

Jacko


1 Answers

If you are using a Windows/PowerShell environment, you have to use $env:GITHUB_ENV instead of $GITHUB_ENV:

    echo "GENERATOR_PLATFORM=$generator" >> $env:GITHUB_ENV

This way, you can access your env var through $env:GENERATOR_PLATFORM, eg:

    run: echo $env:GENERATOR_PLATFORM
like image 58
soltex Avatar answered Jan 05 '23 15:01

soltex