简体   繁体   English

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

[英]no Go files in ... when on making golang deb in gitlab-ci/cd

This is something regarding golang, code of which I am using in gitlab-ci.yml file.这是关于 golang 的,我在 gitlab-ci.yml 文件中使用的代码。 This is the error which I am getting no Go files in /builds/release_management as shown:这是我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

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.请注意:我也尝试过提供$CI_PROJECT_DIR/$BasePathForBinaryFile1并且这也不起作用。

While, this works when I am doing cd first then building it from current using dot(.)虽然,这在我先做 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 .

Here is my folder structure:这是我的文件夹结构:

在此处输入图像描述

Any idea what thing should I fix to fix this golang error?知道我应该修复什么来修复这个 golang 错误吗?

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:编辑 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

There are a few problems:有几个问题:

  1. There is no BinaryName1 in your config so您的配置中没有BinaryName1所以
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.您需要修复配置以使用BinaryName1BinaryName2而不是两次使用BinaryName

  1. You need to specify src dir as ./cmd/main_1/ .您需要将 src 目录指定为./cmd/main_1/
  2. In Edit 1 part cd doesn't work because the env name is incorrect it should be $BasePathForBinaryFile1 but it is $BasePathForBinaryFile .Edit 1部分cd不起作用,因为环境名称不正确它应该是$BasePathForBinaryFile1但它是$BasePathForBinaryFile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM