Gitlab CI Artifacts not found

My Gitlab CI build says it cannot find the files or folders I marked as artifacts.

Here is my .gitlab-ci.yaml

variables:
  REPO_NAME: gitlab.com/sander-playground/deploy-test

before_script:
  - echo $CI_BUILD_REF
  - echo $CI_PROJECT_DIR
stages:
  - build
  - publish

build-project:
  image: golang:1.8-alpine
  stage: build
  script:
    - go version
    - apk add --no-cache git
    - mkdir -p $GOPATH/src/$REPO_NAME
    - mv $CI_PROJECT_DIR/* $GOPATH/src/$REPO_NAME/
    - cd $GOPATH/src/$REPO_NAME
    - go get -v
    - go test -v
    - env GOOS=linux GOARCH=arm go build -o build/deploy-test-arm.bin -v helloworld.go
    - ls -R -la
  artifacts:
    paths:
      - build

publish-image:
  image: docker:git
  stage: publish
  services:
    - docker:dind
  script:
    - ls -R -l
    - docker version
    - docker login -u $CI_DOCKER_U -p $CI_DOCKER_PW registry.hub.docker.com
    - docker build -f Dockerfile-arm -t $REPO_NAME:latest .
    - docker push $REPO_NAME:latest registry.hub.docker.com

Here is the tail of the output of the build stage

$ ls -R -la
.:
total 44760
drwxr-xr-x    3 root     root          4096 Apr 23 12:39 .
drwxr-xr-x    3 root     root          4096 Apr 23 12:39 ..
-rw-rw-rw-    1 root     root           102 Apr 23 12:39 Dockerfile
-rw-rw-rw-    1 root     root           139 Apr 23 12:39 Dockerfile-arm
-rwxrwxrwx    1 root     root           257 Apr 23 12:39 arm-build.sh
drwxr-xr-x    2 root     root          4096 Apr 23 12:39 build
-rwxrwxrwx    1 root     root           113 Apr 23 12:39 build.sh
-rw-rw-rw-    1 root     root            52 Apr 23 12:39 get.sh
-rwxrwxrwx    1 root     root      15932993 Apr 23 12:39 helloworld
-rwxrwxrwx    1 root     root      13939660 Apr 23 12:39 helloworld-arm
-rw-rw-rw-    1 root     root           283 Apr 23 12:39 helloworld.go
-rwxrwxrwx    1 root     root      15863644 Apr 23 12:39 iris-test
-rwxrwxrwx    1 root     root            58 Apr 23 12:39 run.sh

./build:
total 6736
drwxr-xr-x    2 root     root          4096 Apr 23 12:39 .
drwxr-xr-x    3 root     root          4096 Apr 23 12:39 ..
-rwxr-xr-x    1 root     root       6937869 Apr 23 12:39 deploy-test-arm.bin
Uploading artifacts...
WARNING: build: no matching files                  
Uploading artifacts to coordinator... ok            id=14851928 responseStatus=201 Created token=Qi6nfXiy
Job succeeded

So there is a build folder which contains my go build output file, but it seems like GitLab cannot find this folder…

1 Like

Hi,

I see you run a cd command.
As good as I know the path is interpreted from the directory where GitLab places your repository and not from your current location.
So either copy it back to the CI_PROJECT_DIR or define it properly.
This could be a problem.

Cheers

1 Like

Hey, thanks for you response!
You were right, GitLab indeed looks for artifacts in CI_PROJECT_DIR and not in your working directory.
So my build stage worked after I changed my go build command from this:
... go build -o build/deploy-test-arm.bin ...

to this:
... go build -o $CI_PROJECT_DIR/build/deploy-test-arm.bin ...

Thanks again!

1 Like