Create env variables such as this:
env:
global:
- TRAVIS_GOCACHE=$(go env | grep GOCACHE | cut -d "=" -f 2)
Now try to create a cache based on this variable in your matrix:
jobs:
include:
- &backend
language: go
go: 1.12.x
cache:
directories:
- $TRAVIS_GOCACHE
Travis log:
fetching craig-develop/cache-linux-xenial-c3174378f6091b8027b72ca31a800d16e049aa069cf386d5041ac6c4212d9b15--go-1.12.x.tgz
found cache
0.00s1.15sadding /home/travis/gopath/src/github.com/flexera/beacon-monitoring/"/home/travis/.cache/go-build" to cache
creating directory /home/travis/gopath/src/github.com/flexera/beacon-monitoring/"/home/travis/.cache/go-build"
Log onto the machine:
Build fails:
The command "GOOS=$TRAVIS_GOOS GOARCH=$TRAVIS_GOARCH go get -v -t ./..." failed and exited with 1 during .
When reporting a problem, please include relevant build URLs. Thanks.
Note that the TRAVIS_GOCACHE
is assigned a string containing "
:
$ go env | grep GOCACHE | cut -d "=" -f 2
"/home/travis/.cache/go-build"
You can see this in the logs.
My guess is that our caching utilities don’t consider this possibility, and having problems because of it. You probably don’t want to cache this (almost certainly nonexistent) directory, either.
What you can try instead, is to eval
what you want to set (since go env
returns strings with "
in them). For example:
eval export TRAVIS_$(go env | grep GOCACHE)
Notice that you should generally stay away from setting your own $TRAVIS_*
environment variables. We may use them without notice and it can break your builds in unexpected ways.
2 Likes
Is it even legal to put shell commands into variable values? Is this documented somewhere?
I expected anything you provide to be assigned to the variable verbatim.
Well, it works - whether or not it’s legal (in what sense you’re talking about legality I’m not certain) or wanted by the Travis team.
Ultimately, anything you put in there would be interpreted by the shell as it’s an environment variable.
1 Like