linux - 在 jenkins 管道上使用容器运行 go2xunit

标签 linux docker jenkins go

我正在尝试在容器内的 Jenkinspipeline 上运行测试。 它无法找到其中一个二进制文件 /bin/sh:第 2 行:go2xunit:找不到命令

jenkins 测试阶段的片段:

    stage('Tests') {

  steps {
    // NOTE: you must include '|| :' so a failed test does not prevent the
    // junit XML collection from running; any failed tests in the XML will
    // mark the build as UNSTABLE and indicate failed tests in GHE and jenkins
    sh 'make -f Makefile.release test'
    junit 'test/*xml'
  }
}

生成文件.release

.PHONY: test
test:
    @docker run -it -v test:/src/test --rm ${BUILDER_TAG} \
            2>&1 go test  -v -short ./... | \
            go2xunit -output test/test1.xml

docker 文件

FROM golang:1.12.7-alpine AS builder

#Disable cgo
ENV CGO_ENABLED=0

WORKDIR /src

# Packages required for project build and test
RUN apk add --no-cache git make
RUN go get \
        github.com/AlekSi/gocov-xml \
        golang.org/x/lint/golint \
        github.com/axw/gocov \
        github.com/tebeka/go2xunit \
        github.com/wadey/gocovmerge

# These layers are only re-built when Go modules are updated
COPY go.mod go.sum ./
RUN go mod download


# This layer is rebuilt when a file changes in the project directory
COPY . ./

RUN go install ./...

如果我在我的本地机器上给出相同的命令。或者,如果我从容器内运行这些命令,它运行良好。

 C02X37E2JG5J:push3 auser03$ docker run -it d919c2f58e74 /bin/sh
/src # make -f makefile.release test

我可能在这里遗漏了什么。

最佳答案

在运行“go2xunit”命令之前,您必须下载 go2x 作为直接依赖项。

go get github.com/tebeka/go2xunit
go test -v .\... | $(GOPATH)/bin/go2xunit -output test_report.xml

关于linux - 在 jenkins 管道上使用容器运行 go2xunit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57235457/

相关文章:

c - fork 和执行

python-3.x - sam local start-api 在本地测试 SAM 应用程序时出错

php - 如何安装PHP的mysql模块?

jenkins - 通知/检查 Jenkins 中的 SCM 轮询失败

regex - Grep/Sed 每次出现换行符后跟 bash 中的字符串

linux - 剥离尾部字符串时保留 Bash 后缀?

docker - 如何使用 docker inspect --format 从对象获取第一个 key (获取容器网络的名称)

python - 如果特定测试失败,则剩余的 pytest 测试失败

android - Xamarin.Android 安卓 :versionCode android:versionName - From Jenkins Build Server

python - python写的一个正在运行的服务器进程如何查找绑定(bind)地址和端口?