codeclimate / test-reporter

Code Climate Test Reporter
MIT License
156 stars 76 forks source link

golang + jenkins + cover setup #299

Closed sayanee closed 6 years ago

sayanee commented 6 years ago

I have been trying to setup codeclimate with golang and Jenkinsfile, but was unable to find any examples.

I have referred to these resources already:

I am already running the test through Jenkins CI with go test ./... -cover. Any clue to the Jenkinsfile? Thanks a bunch 🙇‍♀️

davehenton commented 6 years ago

Hey @sayanee, thanks for reaching out. To help troubleshoot, could you open up a support ticket here, including the following info:

Send that over when you get a chance, and we'll be happy to take a closer look. Thanks!

davehenton commented 6 years ago

Hey @sayanee, were you able to get this resolved? If not, please write into support with the information listed above, and we'll help get this sorted out. I'll close out this issue for now.

sayanee commented 6 years ago

Thanks @davehenton! Yes I was able to solve it. For the benefit of others stumbling on similar issue, here's a sample code:

In Makefile

PACKAGES = $(shell find . -name '*.go' -exec dirname {} \; | sort --unique)

test:
    echo "mode: set" > c.out
    $(foreach pkg,$(PACKAGES),\
        echo > covsingle.out && \
        go test $(pkg) -coverprofile=covsingle.out -covermode=set && \
        tail -n +2 covsingle.out >> c.out || exit;)
    rm covsingle.out

In Jenkinsfile

...
stages {
    stage("Running tests"){
      steps {
        echo "Running tests"
        sh "cc-test-reporter before-build"
        sh "make test"
        sh "cc-test-reporter after-build --insecure"
      }
    }
...