This is something regarding golang, code of which I am using in gitlab-ci.yml file.
This is the error which I am getting no Go files in /builds/release_management
as shown:
$ pwd
/builds/release_management
$ echo $BasePathForBinaryFile1
cmd/main_1/
$ ls
COPYING
DebPackageGitLabDocker
README.md
cmd
deb-build
ermbuild
go.mod
publishToRemote.sh
usr
working_gitlab-ci_ableToCreateDebPackageWithNoBinary.yml
$ echo $CI_PROJECT_DIR/$BasePathForBinaryFile1
/builds/release_management/cmd/main_1/
$ GOOS=$GOOS GOARCH=$GOARCH go build -o $BinaryName1 $BasePathForBinaryFile1
no Go files in /builds/release_management
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
Here is the code of my job
variables:
GOOS: linux
GOARCH: amd64
TagName: 1.0.71
DebFileName: $TagName
BasePathForBinaryFile1: cmd/main_1/
BinaryName: main1
BasePathForBinaryFile2: cmd/main_2/
BinaryName: main2
build_binary:
stage: build
image: golang:latest
artifacts:
untracked: true
script:
- cd cmd/main_1
- GOOS=$GOOS GOARCH=$GOARCH go build -o $BinaryName1 $BasePathForBinaryFile1
# - GOOS=$GOOS GOARCH=$GOARCH go build -o $BinaryName1 $CI_PROJECT_DIR/$BasePathForBinaryFile1
Please note: I have also tried by giving $CI_PROJECT_DIR/$BasePathForBinaryFile1
and that is also not working.
While, this works when I am doing cd first then building it from current using dot(.)
variables:
GOOS: linux
GOARCH: amd64
TagName: 1.0.71
DebFileName: $TagName
BasePathForBinaryFile1: cmd/main_1/
BinaryName: main1
BasePathForBinaryFile2: cmd/main_2/
BinaryName: main2
build_binary:
stage: build
image: golang:latest
artifacts:
untracked: true
script:
- cd cmd/main_1
- GOOS=$GOOS GOARCH=$GOARCH go build -o $BinaryName .
Here is my folder structure:
Any idea what thing should I fix to fix this golang error?
Edit 1: Also, when doing cd $CI_PROJECT_DIR/$BasePathForBinaryFile
and then ls
it is not going into that directory and still showing content of base directory only:
$ echo $CI_PROJECT_DIR/$BasePathForBinaryFile1
/builds/SugarBox/edge_release_management/cmd/main_1/
$ cd $CI_PROJECT_DIR/$BasePathForBinaryFile
$ ls
COPYING
DebPackageGitLabDocker
README.md
cmd
deb-build
ermbuild
go.mod
publishToRemote.sh
usr
working_gitlab-ci_ableToCreateDebPackageWithNoBinary.yml
CodePudding user response:
There are a few problems:
- There is no
BinaryName1
in your config so
GOOS=$GOOS GOARCH=$GOARCH go build -o $BinaryName1 $BasePathForBinaryFile1
Becomes
GOOS=$GOOS GOARCH=$GOARCH go build -o cmd/main_1/
and the source files are expected in current dir, while they are not there. You need to fix config to have BinaryName1
and BinaryName2
instead of having BinaryName
twice.
- You need to specify src dir as
./cmd/main_1/
. - In
Edit 1
partcd
doesn't work because the env name is incorrect it should be$BasePathForBinaryFile1
but it is$BasePathForBinaryFile
.