Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 385
Shikloshi Avatar asked Dec 01 '15 13:12

Shikloshi


People also ask

Which of the following file is used to configure the Travis CI?

Configuration. Travis CI is configured by adding a file named . travis. yml , which is a YAML format text file, to the root directory of the repository.

Which of the following are among the minimal basic requirements to start working with Travis CI?

Prerequisites # To start using Travis CI, make sure you have: A GitHub or Bitbucket or GitLab or Assembla account. Owner permissions for a project hosted on GitHub or Bitbucket or GitLab or Assembla.


1 Answers

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.

like image 90
Scott Avatar answered Sep 27 '22 23:09

Scott