【发布时间】:2019-11-01 08:54:21
【问题描述】:
我有一个 GitLab ci 管道,但我不知道如何让它在构建阶段生成一个带有二进制文件的工件。
这是我的 yml 文件...
stages:
- test
- build
- art
image: golang:1.9.2
variables:
BIN_NAME: example
ARTIFACTS_DIR: artifacts
GO_PROJECT: example
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
# Execute the binary
- ./hello
art:
script:
artifacts:
paths:
- ./hello
测试和构建阶段运行良好,但艺术阶段在添加到 yml 文件时却没有。
我在网上找到了很多示例,但很难将它们转换为我的确切情况。
我只想让工件以下载的形式出现在管道上,就像在这个链接中一样。
在尝试了建议的解决方案后,我得到了以下...
$ go build -o hello
$ ./hello
Heldfgdfglo 2
Uploading artifacts...
WARNING: ./hello: no matching files
ERROR: No files to upload
Job succeeded
尝试添加..
GOPATH: /go
还有……
- cd ${GOPATH}/src/${GO_PROJECT}
现在出现以下错误...
Uploading artifacts...
WARNING: /go/src/example/hello: no matching files
ERROR: No files to upload
Job succeeded
按要求共享输出...
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}
$ go build -o hello
$ pwd
/go/src/example
$ ls -l hello
-rwxr-xr-x. 1 root root 1859961 Jun 19 08:27 hello
$ ./hello
Heldfgdfglo 2
Uploading artifacts...
WARNING: /go/src/example/hello: no matching files
ERROR: No files to upload
Job succeeded
【问题讨论】: