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

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)?

  • 写回答

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`

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?