2015-10-13 37 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

    相關問題