2015-10-13 85 views
3

我有一个Go项目,我想用Travis-CI构建并将其部署到特定的提供程序。 我熟悉Gimme project,它将使用交叉编译来实现。 但是因为Travis已经支持linux和osx我只需要这个功能的Windows版本。Travis CI + Go:为不同的操作系统创建特定的构建流程

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

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

  1. 本地Linux/OS版本(与 “OS” 一节)。使用Gimmme

对于第一种选择将是这个样子的.travis.yml文件

  • 的Windows编译:

    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 
    

    是否有一个很好的干净的方式来结合这两个(与环境变量或任何其他疯狂的想法)?

  • 回答

    2

    这可能是简单的,但矩阵environement不能针对特定的操作系统来完成...

    然后,只需与当地environement变量选择:

    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 
    

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

    注:的environament变量可以是accessibe:http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables或致电\ printenv`

    +0

    谢谢,这是伟大的! – Shikloshi

    相关问题