dsd57259
2015-10-13 19:48
浏览 63
已采纳

Travis CI + Go:为不同的操作系统创建特定的构建流程

I have a Go project that I want to build with Travis-CI and deploy it to a specific provider. I familiar with Gimme project that will use a cross-compilation to do so. But because Travis already support linux and osx I only need this feature for Windows build.

The big motivation is, of course, to avoid cross-compilation run time error as there are plenty of it.

My question is how can I create, in the same .travis.yml file, a different build flow:

  1. Native linux/os build (with "os" section).
  2. Windows compilation using Gimmme

The .travis.yml file for the first option will look something like:

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

The .travis.yml file for the second option will look something like:

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

Is there a nice clean way to combine these two (with Environment variables or any other crazy idea)?

图片转代码服务由CSDN问答提供 功能建议

我有一个要使用Travis-CI构建的Go项目,并将其部署到特定的提供程序。 I 熟悉 Gimme项目,该项目将使用交叉编译来实现。 但是因为Travis已经支持 linux和osx我只需要Windows构建此功能。

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

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

  1. 本地linux / os构建(带有“ os”部分)。
  2. 使用Gimmme的Windows编译

    第一个选项的.travis.yml文件如下所示: < pre> 语言:go go: -1.5.1 分支: only: -master os: -osx -linux \ nbefore_script: -去获取-d -v ./... script: -去编译-v ./... #-去测试-v ./... before_deploy : -chmod + x ./before_deploy.sh -./before_deploy.sh

    第二个选项的.travis.yml文件看起来像 像:

     语言:go 
     
    go:
    -1.5.1 
     
    分支:
    仅:
    -母版
     
    env:
      -GIMME_OS = windows GIMME_ARCH = amd64 
     
     
    before_script:
    -go get -d -v ./...
    
    script:
    -go b  uild -v ./...
    #-测试-v ./...
    
    before_deploy:
    -chmod + x ./before_deploy.sh
    -./before_deploy.sh
      
     
     

    是否有一种很好的干净方法将这两者结合在一起(与环境变量或任何其他疯狂的主意)?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doucuan5365 2015-10-16 08:34
    已采纳

    It might be simple, but matrix environement can not be done for a specific OS ...

    Then just select with local environement variable:

    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
    

    An other way:

    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
    

    Note: the commande: - chmod +x ./before_deploy.sh can be directly done in your repository and commited on it ...

    Note: The environament variable can be accessibe: http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables or calling \printenv`

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题