When making golang deb in gitlab-ci/cd, there are no Go files in...

王林
Release: 2024-02-13 13:50:09
forward
472 people have browsed it

在 gitlab-ci/cd 中制作 golang deb 时,...中没有 Go 文件

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.

Question content

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
Copy after login

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
Copy after login

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 .
Copy after login

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
Copy after login

Solution

There are several problems:

  1. There is no binaryname1
  2. in your configuration
goos=$goos goarch=$goarch go build -o $binaryname1 $basepathforbinaryfile1
Copy after login

become

GOOS=$GOOS GOARCH=$GOARCH go build -o cmd/main_1/
Copy after login

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.

  1. You need to specify the src directory as ./cmd/main_1/.
  2. In 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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!