【问题标题】:Travis CI + Go: creating a specific build flow for different OSTravis CI + Go:为不同的操作系统创建特定的构建流程
【发布时间】:2015-10-13 19:48:57
【问题描述】:

我有一个 Go 项目,我想使用 Travis-CI 构建并将其部署到特定的提供商。 我熟悉Gimme project,它将使用交叉编译来做到这一点。 但是因为 Travis 已经支持 linux 和 osx 我只需要这个功能来构建 Windows。

当然,最大的动机是避免交叉编译运行时错误,因为它有很多。

我的问题是如何在同一个 .travis.yml 文件中创建不同的构建流程:

  1. 原生 linux/os 构建(带有“os”部分)。
  2. 使用 Gimmme 进行 Windows 编译

第一个选项的 .travis.yml 文件如下所示:

language: go

go: 
  - 1.5.1

branches: 
  only: 
    - master

os:
    - osx
    - linux


before_script:
    - go get -d -v ./...

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

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

第二个选项的 .travis.yml 文件如下所示:

language: go

go: 
  - 1.5.1

branches: 
  only: 
    - master

env:
    - GIMME_OS=windows GIMME_ARCH=amd64


before_script:
    - go get -d -v ./...

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

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

有没有一种干净的方式来结合这两者(使用环境变量或任何其他疯狂的想法)?

【问题讨论】:

    标签: go operating-system cross-compiling travis-ci


    【解决方案1】:

    这可能很简单,但是对于特定的操作系统,矩阵环境无法完成......

    然后只需选择本地环境变量:

    language: go
    go: 
      - 1.5.1
    branches: 
      only: 
        - master
    os:
      - osx
      - linux
    install:
      - if [ "$TRAVIS_OS_NAME" == "linux" ]; then
            export GIMME_OS=windows;
            export GIMME_ARCH=amd64;
        fi
    before_script:
      - go get -d -v ./...
    script:
      - go build -v ./...
    after_script:
      - go test -v ./...
    before_deploy: 
      - ./before_deploy.sh
    

    另一种方式:

    language: go
    go: 
      - 1.5.1
    branches: 
      only: 
        - master
    matrix:
      include:
        - os: linux
          env: GIMME_OS=windows; GIMME_ARCH=amd64;
        - os: osx
    before_script:
      - go get -d -v ./...
    script:
      - go build -v ./...
    after_script:
      - go test -v ./...
    before_deploy: 
      - ./before_deploy.sh
    

    注意:命令:- chmod +x ./before_deploy.sh 可以直接在您的存储库中完成并提交...

    注意:环境变量可以访问:http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables或调用\printenv`

    【讨论】:

    • 谢谢,太好了!
    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    相关资源
    最近更新 更多