GO_VERSION as environment variable stopped working

We are reading the go version from a file in our repository and load it into an environment variable. About 3 days ago this stopped working. Looking at Compatibility with GOPATH and Modules (go.mod present) and https://github.com/travis-ci/travis-build/pull/1636 by @meatballhat this might be related, especially because of the timing of the issue. I didn’t dig into the PR but there seem to be quite some changes to GO_VERSION.

For now we switched to hardcode the version and things keep working. Here is the PR to reintroduce usage of the environment variable: https://github.com/elastic/beats/pull/10589 I played around with some different environment vars but no luck yet.

The error we get is:

Setting environment variables from .travis.yml
$ export GOX_FLAGS="-arch amd64"
$ export DOCKER_COMPOSE_VERSION=1.21.0
$ export GO_VERSION="$(cat .go-version)"
$ export TRAVIS_MINIKUBE_VERSION=v0.25.2
$ export TARGETS="check"
23.14s$ travis_setup_go $GO_VERSION github.com/elastic/beats
gimme: version specifier '$GO_VERSION' unknown
error: GIMME_GO_VERSION not recognized as valid
  got: $GO_VERSION
Failed to run gimme
The command "travis_setup_go $GO_VERSION github.com/elastic/beats" failed and exited with 86 during .

@ruflin Thanks for bringing this up! This usage with defining GO_VERSION is new for me, but I would assume it could work. Please note that any value given to the go: key will be escaped, which is (I assume) why the error you’ve posted is happening.

Do you think a solution like this could work for you?

travis_setup_go "$(cat .go-version)" github.com/elastic/beats

It has the unfortunate quality of running travis_setup_go twice, so maybe it would be better (and I would prefer) for the default setup step to be literally:

travis_setup_go  "${TRAVIS_GO_VERSION}" "${TRAVIS_GO_IMPORT_PATH}"

and the dereferenced values could be echo’d to the log.

@ruflin The current production code (deployed ~30m ago) will respect ${TRAVIS_GO_VERSION} however you wish to define it, including:

env:
  global:
  - TRAVIS_GO_VERSION="$(cat .go-version)"
1 Like

Hi @meatballhat Thanks a lot for the details. We used the config with the GO_VERSION for at least the last 12 months and worked perfectly.

For us it’s less important which variable it is then that it doesn’t change. Having GO_VERSION not working anymore meant all PR’s to release branches went red so we had to fix all them.

I just started a build with - TRAVIS_GO_VERSION="$(cat .go-version)" and so far all looks good: https://travis-ci.org/elastic/beats/builds/492049126?utm_source=github_status&utm_medium=notification

Thanks again @meatballhat