gitlab ci cache/keep golang packages between stages

Viewed 6327

I use gitlab-ci to test, compile and deploy a small golang application but the problem is that the stages take longer than necessary because they have to fetch all of the dependencies every time.

How can I keep the golang dependencies between two stages (test and build)?

This is part of my current gitlab-ci config:

test:
    stage: test
    script:
        # get dependencies
        - go get github.com/foobar/...
        - go get github.com/foobar2/...
        # ...
        - go tool vet -composites=false -shadow=true *.go
        - go test -race $(go list ./... | grep -v /vendor/)

compile:
    stage: build
    script:
        # getting the same dependencies again
        - go get github.com/foobar/...
        - go get github.com/foobar2/...
        # ...
        - go build -race -ldflags "-extldflags '-static'" -o foobar
    artifacts:
        paths:
            - foobar
2 Answers
Related