VOL-2057 Ensure Makefile variables set correctly when tools are missing

Change-Id: I9540d579525eb55c5fa79cde2370f7d83985ecd4
diff --git a/Makefile b/Makefile
index 5e492bf..ba5f74d 100644
--- a/Makefile
+++ b/Makefile
@@ -143,30 +143,44 @@
 
 lint: lint-style lint-sanity lint-mod lint-dockerfile
 
-GO_JUNIT_REPORT:=$(shell which go-junit-report)
-GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
-
-GOLANGCI_LINT_TOOL:=$(shell which golangci-lint)
-sca:
+# Rules to automatically install golangci-lint
+GOLANGCI_LINT_TOOL?=$(shell which golangci-lint)
 ifeq (,$(GOLANGCI_LINT_TOOL))
-	@echo "Please install golangci-lint tool to run sca"
-	exit 1
+GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint
+golangci_lint_tool_install:
+	# Same version as installed by Jenkins ci-management
+	# Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint
+	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0
+else
+golangci_lint_tool_install:
 endif
+
+# Rules to automatically install go-junit-report
+GO_JUNIT_REPORT?=$(shell which go-junit-report)
+ifeq (,$(GO_JUNIT_REPORT))
+GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
+go_junit_install:
+	go get -u github.com/jstemmer/go-junit-report
+else
+go_junit_install:
+endif
+
+# Rules to automatically install gocover-covertura
+GOCOVER_COBERTURA?=$(shell which gocover-cobertura)
+ifeq (,$(GOCOVER_COBERTURA))
+	@GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
+gocover_cobertura_install:
+	go get -u github.com/t-yuki/gocover-cobertura
+else
+gocover_cobertura_install:
+endif
+
+sca: golangci_lint_tool_install
 	rm -rf ./sca-report
 	@mkdir -p ./sca-report
-	$(GOLANGCI_LINT_TOOL) run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml ;\
-	RETURN=$$? ;\
-	exit $$RETURN
+	$(GOLANGCI_LINT_TOOL) run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
 
-test:
-ifeq (,$(GO_JUNIT_REPORT))
-	go get -u github.com/jstemmer/go-junit-report
-	@GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
-endif
-ifeq (,$(GOCOVER_COBERTURA))
-	go get -u github.com/t-yuki/gocover-cobertura
-	@GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
-endif
+test: go_junit_install gocover_cobertura_install
 	@mkdir -p ./tests/results
 	@go test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
 	RETURN=$$? ;\