How to use system environment variable in cache actions path? #27163
-
I am trying to access the Windows environment variable
But when it runs, the variable is empty: https://github.com/evandrocoan/TestGithubActions/runs/535518431?check_suite_focus=true#step:9:2
How to access system-defined variables? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @evandrocoan , In default, system environment variable is not included in env context, you could use set-env command to set the value of system Please see my example:
|
Beta Was this translation helpful? Give feedback.
-
@yanjingzhu set-env is now deprecated [0]. Any guidance on how to use an environment variable for caching after this change? Cheers! [0] GitHub Actions: Deprecating set-env and add-path commands - GitHub Changelog |
Beta Was this translation helpful? Give feedback.
-
This is what I have so far: name: Test cache
on:
push:
branches:
- develop
pull_request:
branches:
- develop
jobs:
download-backend:
name: Download backend dependencies (${{ matrix.os }}, ${{ matrix.arch }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- windows-2019
- ubuntu-latest
arch:
- amd64
- arm64
env:
- name: Set up Go 1.19
uses: actions/setup-go@v4
with:
go-version: 1.19
- name: Add go paths to environment
shell: bash
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
echo "GOBIN=$(go env GOBIN)" >> $GITHUB_ENV
- name: Verify go modules are cached
uses: actions/cache@v3
id: cache-go-modules
with:
path: |
${{ env.GOCACHE }}
${{ env.GOMODCACHE }}
${{ env.GOBIN }}
key: go-modules-cache-${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('**/go.sum') }}
- name: Install missing Golang dependencies
if: steps.cache-go-modules.outputs.cache-hit != 'true'
run: go mod download |
Beta Was this translation helpful? Give feedback.
Hi @evandrocoan ,
In default, system environment variable is not included in env context, you could use set-env command to set the value of system
ProgramFiles
to an job env. And then you it with ${{ env.ProgramFilesPath }} syntax.Please see my example: