英文:
no Go files in ... when on making golang deb in gitlab-ci/cd
问题
这是关于golang的一些内容,我在gitlab-ci.yml文件中使用的代码。
这是我得到的错误信息no Go files in /builds/release_management
,如下所示:
$ 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
这是我的作业代码:
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
请注意:我也尝试过使用$CI_PROJECT_DIR/$BasePathForBinaryFile1
,但也没有起作用。
然而,当我先使用cd
命令进入目录,然后使用点号(.
)从当前目录构建时,它可以工作:
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 .
这是我的文件夹结构:
有任何想法可以解决这个golang错误吗?
编辑1: 另外,当执行cd $CI_PROJECT_DIR/$BasePathForBinaryFile
然后ls
时,它不会进入该目录,仍然只显示基本目录的内容:
$ 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
英文:
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
答案1
得分: 0
有几个问题:
- 在你的配置中没有
BinaryName1
,所以
GOOS=$GOOS GOARCH=$GOARCH go build -o $BinaryName1 $BasePathForBinaryFile1
变成了
GOOS=$GOOS GOARCH=$GOARCH go build -o cmd/main_1/
而源文件应该在当前目录中,但实际上并不存在。你需要修复配置,将BinaryName1
和BinaryName2
分别替换为BinaryName
。
- 你需要将源目录指定为
./cmd/main_1/
。 - 在
Edit 1
部分,cd
命令无法工作,因为环境变量名称不正确,应该是$BasePathForBinaryFile1
,而不是$BasePathForBinaryFile
。
英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论