我有一个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
测试和构建阶段运行良好,但是将art阶段添加到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
答案 0 :(得分:1)
您需要在创建它们的作业中指定您的工件路径,因为每个作业都会触发一个新的空环境(或多或少考虑了缓存):
build:
stage: build
script:
# Compile and name the binary as `hello`
- go build -o hello
# Execute the binary
- ./hello
artifacts:
paths:
- ./hello
答案 1 :(得分:1)
./hello
与您的工件路径不匹配,因为您在运行脚本之前更改了目录。
您需要将生成的可执行文件移动到gitlab运行程序的原始工作目录中,因为工件路径只能相对于构建目录:
build:
stage: build
script:
# Compile and name the binary as `hello`
- go build -o hello
# Execute the binary
- ./hello
# Move to gitlab build directory
- mv ./hello ${CI_PROJECT_DIR}
artifacts:
paths:
- ./hello