php editor Xigua will introduce you to a common problem when making golang deb in gitlab-ci/cd. Sometimes, when we try to make golang deb package in gitlab-ci/cd, we may encounter an error that "No Go file in...". The reason for this error is because there are no Go files in the root directory of the project. Next, we will explain to you in detail how to solve this problem so that you can successfully create golang deb packages.
This is about golang, whose code I use in the gitlab-ci.yml file.
This is the error I'm getting for no go files in /builds/release_management
like this:
$ 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
This is my working code
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 also tried giving $ci_project_dir/$basepathforbinaryfile1
but that didn't work either.
Although, this only works when I first do a cd and then use dot(.) to build it from the current one
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 .
This is my folder structure:
Any idea what I should fix to fix this golang error?
Edit 1: Also, when doing cd $ci_project_dir/$basepathforbinaryfile
and then ls
, it does not go into the directory and still only shows Contents of the base directory:
$ 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
There are several problems:
binaryname1
goos=$goos goarch=$goarch go build -o $binaryname1 $basepathforbinaryfile1
become
GOOS=$GOOS GOARCH=$GOARCH go build -o cmd/main_1/
The source file should be located in the current directory, but does not exist. You need to fix the configuration to have binaryname1
and binaryname2
instead of binaryname
twice.
./cmd/main_1/
. edit 1
section cd
does not work because the environment name is incorrect, it should be $basepathforbinaryfile1
but it is $basepathforbinaryfile
. The above is the detailed content of When making golang deb in gitlab-ci/cd, there are no Go files in.... For more information, please follow other related articles on the PHP Chinese website!