Might be late to this question, but for anyone else whose searches came here - I managed to get it to work like this:
withEnv(['GOPATH=' + pwd()]){ dir ('src/github.com/username') { // insert git checkout here sh 'go build -o $GOPATH/my-bin-file' } } -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b0869c7c-21aa-4781-abbc-ec7bc5831f0e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.