Travis-CI: Using environment variables in the deploy section of the .travis.yml file
Asked Answered
C

1

6

I'm using Travis-CI to build my Go project and so far I used the gimme script with combination of travis go environment to cross-compile the project.

I switch to Go 1.5 that supports the GOOS and GOARCH environment variables to cross compiler without the need of other compilers or scripts.

My problems is that I'm using Bintray deploy and my environment variables are not exposed in the deploy phase.

language: go

go:
  - 1.5

env:
    matrix:
       - GOOS=windows GOARCH=amd64
       - GOOS=linux GOARCH=amd64
       - GOOS=linux GOARCH=386
       - GOOS=darwin GOARCH=amd64
before_script:
  - go get -d -v ./...

script:
  - go build -v ./...

before_deploy:
  - chmod +x ./prepare_bintray_deployment.sh
  - "./prepare_bintray_deployment.sh"

deploy:
  file: bintray_descriptors/${GOOS}_${GOARCH}.json
  provider: bintray

Note that before this change I was using the GIMME_OS and GIMME_ARCH environment variables and it worked fine and this makes me believe that Travis does support this.

What could be the problem?

Christiansand answered 1/12, 2015 at 13:25 Comment(1)
I want to set the environment variable for my deploy in Travis CI too. Did you find out the solution to perform this?Fluorite
B
1

Something like this worked for me:

script:
  - # do some build stuff here
  - echo ${MY_VAR} > my_var.txt

before_deploy:
  - export MY_VAR=$(cat my_var.txt)

deploy:
  file: foo/bar_${MY_VAR}.json
  skip_cleanup: true

Essentially, you can't seem to access dynamic vars exported from the script section in the deploy section, but you can write them down (output to a file) and then access them later.

Bonefish answered 27/6, 2018 at 16:43 Comment(1)
For others who encounter this solution. It seems that this workaround is no longer necessary. I had some difficulties by using foo/bar_$MY_VAR.json, which were solved when using foo/bar_${MY_VAR}.jsonCrofton

© 2022 - 2024 — McMap. All rights reserved.