doufan3958 2019-06-19 09:29 采纳率: 0%
浏览 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

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

报告相同问题?