Golangci-lint: Unable to run golangci-lint in jenkins build

Created on 8 Jul 2020  路  5Comments  路  Source: golangci/golangci-lint

Thank you for creating the issue!

  • [x] Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • [x] Yes, I've searched similar issues on GitHub and didn't find any.
  • [x] Yes, I've included all information below (version, config, etc).

Please include the following information:

Version of golangci-lint

1.27

Config file

Using the default config.

Go environment

12:56:09 + go version
12:56:09 go version go1.14.4 linux/amd64
12:56:09 + go env
12:56:09 GO111MODULE=""
12:56:09 GOARCH="amd64"
12:56:09 GOBIN=""
12:56:09 GOCACHE="/var/jenkins_home/.cache/go-build"
12:56:09 GOENV="/var/jenkins_home/.config/go/env"
12:56:09 GOEXE=""
12:56:09 GOFLAGS=""
12:56:09 GOHOSTARCH="amd64"
12:56:09 GOHOSTOS="linux"
12:56:09 GOINSECURE=""
12:56:09 GONOPROXY=""
12:56:09 GONOSUMDB=""
12:56:09 GOOS="linux"
12:56:09 GOPATH="/var/jenkins_home/workspace/Auto-Quote-Builds/golang-backend-fabxprime"
12:56:09 GOPRIVATE=""
12:56:09 GOPROXY="https://proxy.golang.org,direct"
12:56:09 GOROOT="/var/jenkins_home/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go_1.14.4_golang.org"
12:56:09 GOSUMDB="sum.golang.org"
12:56:09 GOTMPDIR=""
12:56:09 GOTOOLDIR="/var/jenkins_home/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go_1.14.4_golang.org/pkg/tool/linux_amd64"
12:56:09 GCCGO="gccgo"
12:56:09 AR="ar"
12:56:09 CC="gcc"
12:56:09 CXX="g++"
12:56:09 CGO_ENABLED="1"
12:56:09 GOMOD="/var/jenkins_home/workspace/Auto-Quote-Builds/golang-backend-fabxprime/src/fabxprime/go.mod"
12:56:09 CGO_CFLAGS="-g -O2"
12:56:09 CGO_CPPFLAGS=""
12:56:09 CGO_CXXFLAGS="-g -O2"
12:56:09 CGO_FFLAGS="-g -O2"
12:56:09 CGO_LDFLAGS="-g -O2"
12:56:09 PKG_CONFIG="pkg-config"
12:56:09 GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build483847592=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

12:59:54 level=info msg="[config_reader] Config search paths: [./ /var/jenkins_home/workspace/Auto-Quote-Builds/golang-backend-fabxprime/src /var/jenkins_home/workspace/Auto-Quote-Builds/golang-backend-fabxprime /var/jenkins_home/workspace/Auto-Quote-Builds /var/jenkins_home/workspace /var/jenkins_home /var /]"
12:59:54 level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
12:59:54 level=info msg="[loader] Go packages loading at mode 575 (exports_file|files|types_sizes|compiled_files|deps|imports|name) took 115.918513ms"
12:59:54 level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 6.680432ms"

12:59:58 level=info msg="[linters context/goanalysis] analyzers took 4.951727904s with top 10 stages: buildir: 3.96913234s, inspect: 450.121678ms, fact_purity: 176.493431ms, ctrlflow: 150.991633ms, fact_deprecated: 99.68408ms, printf: 93.605028ms, S1031: 560.454碌s, lostcancel: 177.128碌s, ineffassign: 175.219碌s, S1005: 168.752碌s"
12:59:58 level=warning msg="[runner] Can't run linter goanalysis_metalinter: S1002: failed prerequisites: [(inspect@fabxprime/utils, isgenerated@fabxprime/utils): analysis skipped: errors in package: [/var/jenkins_home/workspace/Auto-Quote-Builds/golang-backend-fabxprime/src/fabxprime/utils/UploadFilesToAzure.go:12:2: could not import github.com/Azure/azure-storage-blob-go/azblob (/var/jenkins_home/workspace/Auto-Quote-Builds/golang-backend-fabxprime/src/fabxprime/vendor/github.com/Azure/azure-storage-blob-go/azblob/chunkwriting.go:13:8: could not import github.com/google/uuid (/var/jenkins_home/workspace/Auto-Quote-Builds/golang-backend-fabxprime/src/fabxprime/vendor/github.com/google/uuid/node_net.go:9:8: could not import net (/var/jenkins_home/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go_1.14.4_golang.org/src/net/cgo_linux.go:12:8: could not import C (cgo preprocessing failed))))]]"
12:59:58 level=info msg="[linters context/goanalysis] analyzers took 4.751356ms with top 10 stages: buildir: 4.426485ms, U1000: 324.871碌s"
12:59:58 level=warning msg="[runner] Can't run linter unused: buildir: failed to load package net: could not load export data: no export data for \"net\""
12:59:58 level=info msg="[runner] processing took 3.333碌s with stages: max_same_issues: 636ns, nolint: 420ns, skip_dirs: 402ns, cgo: 283ns, skip_files: 218ns, max_from_linter: 214ns, autogenerated_exclude: 178ns, filename_unadjuster: 177ns, identifier_marker: 169ns, path_prettifier: 129ns, diff: 121ns, uniq_by_line: 111ns, max_per_file_from_linter: 63ns, exclude-rules: 60ns, path_shortener: 53ns, exclude: 51ns, source_code: 48ns"
12:59:58 level=info msg="[runner] linters took 4.532323396s with stages: goanalysis_metalinter: 4.080827626s, unused: 451.456917ms"
12:59:58 level=error msg="Running error: buildir: failed to load package net: could not load export data: no export data for \"net\""
12:59:58 level=info msg="Memory: 48 samples, avg is 439.6MB, max is 605.8MB"
12:59:58 level=info msg="Execution took 4.659162568s"

bug

Most helpful comment

I was seeing the same problem with Go installed from official binaries (i.e. https://golang.org/doc/install). It turned out that net imports cgo_linux, which in turn is including netdb.h.
Bottom line: needed to install gcc and libc-dev packages.
Guess that (some) linters are not differentiating between pure-Go/CGo based implementations, like the compiler itself does?

EDIT: Actually, explicitly setting CGO_ENABLED=0 seems to work, too.

All 5 comments

Hey, thank you for opening your first Issue ! 馃檪 If you would like to contribute we have a guide for contributors.

How do you run the linter? And what is a structure of your project?
The logs has this error:

Can't run linter unused: buildir: failed to load package net: could not load export data: no export data for \"net\"

Probably something wrong with you net package

How do you run the linter? And what is a structure of your project?
The logs has this error:

Can't run linter unused: buildir: failed to load package net: could not load export data: no export data for "net"

Probably something wrong with you net package

Hello, I'm running golangci-lint run on the parent directory of the projects src directory.

The same commands works on my linux system with the same version of golang and golangci-lint. I am unable to debug why its failing to run on jenkins. I'm also using go mod for package management with the go.mod file inside the src directory.

Also, I dont think anything is wrong with net package, as I am able to build the project perfectly fine in jenkins

I was seeing the same problem with Go installed from official binaries (i.e. https://golang.org/doc/install). It turned out that net imports cgo_linux, which in turn is including netdb.h.
Bottom line: needed to install gcc and libc-dev packages.
Guess that (some) linters are not differentiating between pure-Go/CGo based implementations, like the compiler itself does?

EDIT: Actually, explicitly setting CGO_ENABLED=0 seems to work, too.

I was seeing the same problem with Go installed from official binaries (i.e. https://golang.org/doc/install). It turned out that net imports cgo_linux, which in turn is including netdb.h.
Bottom line: needed to install gcc and libc-dev packages.
Guess that (some) linters are not differentiating between pure-Go/CGo based implementations, like the compiler itself does?

EDIT: Actually, explicitly setting CGO_ENABLED=0 seems to work, too.

Thank you @KenjiTakahashi

I was finally able to get it working. I will close the issue as the problem is solved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alessio picture alessio  路  4Comments

ferhatelmas picture ferhatelmas  路  4Comments

jirfag picture jirfag  路  3Comments

nektro picture nektro  路  3Comments

liubog2008 picture liubog2008  路  3Comments