Reputation: 804
I have a GitLab ci pipeline and I am not sure how to get it to generate an artifact with the binary file that happened in the build stage.
Here is my yml file...
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
The test and build phases run fine but the art stage does not when it is added to the yml file.
I have found lots of examples on line but finding it hard to convert them to my exact situation.
All I want to for the artifact to appear as a download on the pipeline like in this link.
after trying solution suggested i get the following...
$ go build -o hello
$ ./hello
Heldfgdfglo 2
Uploading artifacts...
WARNING: ./hello: no matching files
ERROR: No files to upload
Job succeeded
Tried adding..
GOPATH: /go
and...
- cd ${GOPATH}/src/${GO_PROJECT}
now getting following error...
Uploading artifacts...
WARNING: /go/src/example/hello: no matching files
ERROR: No files to upload
Job succeeded
output shared as requested...
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
Upvotes: 2
Views: 8177
Reputation: 1865
./hello
is not matching your artifact path because you changed the directory before running your script.
You need to move the generated executable to the original working directory of the gitlab runner, because artifact paths can only be relative to the build directory:
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
See https://gitlab.com/gitlab-org/gitlab-ce/issues/15530
Upvotes: 2
Reputation: 4188
You need to specify your artifact paths in the job that creates them, since every job triggers a new, empty environment (more or less considering the cache):
build:
stage: build
script:
# Compile and name the binary as `hello`
- go build -o hello
# Execute the binary
- ./hello
artifacts:
paths:
- ./hello
Upvotes: 2