繁体   English   中英

如何将输入文件添加到 TeamCity 中的 bazel 运行

[英]How to add input files to bazel run in TeamCity

我对bazel非常陌生,所以很多理解可能是错误的。

我有一个具有以下结构的本地目录:

/my/certain/path
|- my_test.go
|- my_utils.go
|- BUILD.bazel       
|- mydir 
     |- input1
     |- input2

我在 TeamCity 中使用bazel run运行 go 测试,其中my_test.go (一些敏感信息被替换为xxx... ):

bazel run \
  //my/certain/path:my_test \
  --config=crosslinux --config=test \
  --test_timeout=1800

/my/certain/path/BUILD.bazel我有

go_library(
    name = "path",
    srcs = ["my_utils.go"],
    importpath = "/my/certain/path",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_docker_docker//api/types",
         ...
        "@org_golang_x_net//context",
    ],
)
go_test(
    name = "my_test",
    size = "enormous",
    srcs = ["my_test.go"],
    embed = [":xxx"],
    deps = [
        "//pkg/util/contextutil",
        "//pkg/util/log",
        "@com_github_docker_docker//client",
        "@org_golang_x_net//context",
    ],
)

my_test.go实际上会在运行时使用mydir中的文件作为输入。

但是在 teamcity 上运行时,我注意到mydir没有安装在发生此 bazel 测试的临时目录中,这导致my_test.go失败。

我试图通过添加这些行来打印出当前目录和my_test.go中的所有文件来解决它:

    fmt.Println("==== listing all files in go====")
    err := filepath.Walk(".",
        func(path string, info os.FileInfo, err error) error {
            if err != nil {
                return err
            }
            fmt.Println(path, info.Size())
            return nil
        })
    if err != nil {
        t.Fatal(err)
    }
    fmt.Println("==== end listing all files in go====")

    ctx := context.Background()
    pwd, err := os.Getwd()
    if err != nil {
        t.Fatal(fmt.Errorf("cannot get pwd: %v", err))
    }
    fmt.Println("-----pwd:", pwd)

它表明,

    ==== listing all files in go====
17:26:17     . 4096
17:26:17     my_test_ 4096
17:26:17     my_test_/my_test 152
17:26:17     ==== end listing all files in go====
pwd: /home/agent/.cache/bazel/_bazel_agent/xxxxx/execroot/myname/bazel-out/k8-fastbuild/bin/my/path/my_test_/my_test.runfiles/my/certain/path

所以我的目标是将mydir挂载到这个工作目录( /home/agent/.cache/bazel/_bazel_agent/xxxxx/execroot/myname/bazel-out/k8-fastbuild/bin/my/path/my_test_/ /home/agent/.cache/bazel/_bazel_agent/xxxxx/execroot/myname/bazel-out/k8-fastbuild/bin/my/path/my_test_/my_test.runfiles/my/certain/path )。

我不确定这是 TeamCity 的特定问题,还是 bazel 有办法指定它。

我通过在BUILD.bazel中添加data条目来解决它:

go_test(
    name = "my_test",
    size = "enormous",
    srcs = ["my_test.go"],
    embed = [":xxx"],
    data = glob([
            "mydir/**",
    ]),
    deps = [
        "//pkg/util/contextutil",
        "//pkg/util/log",
        "@com_github_docker_docker//client",
        "@org_golang_x_net//context",
    ],
)

暂无
暂无

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

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