doufan3958 2019-06-19 09:29
浏览 106
已采纳

如何使用Windows的GitLab管道进行构建

I have the following .gitlab-ci.yml...

stages:
  - test
  - build
  - art

image: golang:1.9.2

variables:
  BIN_NAME: example
  ARTIFACTS_DIR: artifacts
  GO_PROJECT: example
  GOPATH: /go


before_script:
  - mkdir -p ${GOPATH}/src/${GO_PROJECT}
  - mkdir -p ${CI_PROJECT_DIR}/${ARTIFACTS_DIR}
  - go get -u github.com/golang/dep/cmd/dep
  - cp -r ${CI_PROJECT_DIR}/* ${GOPATH}/src/${GO_PROJECT}/
  - cd ${GOPATH}/src/${GO_PROJECT}

test:
  stage: test


  script:
    # Run all tests
    go test -run ''


build:
  stage: build

  script:
    # Compile and name the binary as `hello`
    - go build -o hello
    - pwd
    - ls -l hello
    # Execute the binary
    - ./hello
    # Move to gitlab build directory
    - mv ./hello ${CI_PROJECT_DIR}
  artifacts:
    paths:
    - ./hello

This works great for linux but i now need to do the same so that it builds a windows executable.

I then plan to run a scheduled script to download the artifacts.

The other option is I run a virtual linux server on the windows server and use that to run my go binarys. I know i need to change the image to windows but can't see to find an appropriate one online (one that is configured for golang).

Or is it possible to have this docker image build a windows exe?

  • 写回答

1条回答 默认 最新

  • duanhui5344 2019-06-19 19:35
    关注

    This is not a gitlab question, but a go question.

    Since Go version 1.5 cross-compiling has become very easy.

    GOOS=windows GOARCH=386 go build -o hello.exe hello.go
    

    You can now run hello.exe on a Windows machine

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条