You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab流水线中xk6构建Prometheus远程写入插件遇Go版本无效错误

解决xk6构建时Go模块解析错误(go.k6.io/k6@0.44.1版本无效)

问题场景

在GitLab流水线中基于Golang镜像,安装xk6并构建带有github.com/grafana/xk6-output-prometheus-remote插件的k6时,出现Go模块解析错误,提示go.k6.io/k6@0.44.1版本无效、未知修订版本。更换Golang 1.19镜像及不同xk6版本后问题仍存在。

GitLab作业配置

run:k6:
  stage: run
  environment: DEV
  variables:
    GIT_CHECKOUT: "false"
  image:
    name: golang
  needs:
    - job: build:k6
  script:
    - go install go.k6.io/xk6/cmd/xk6@latest
    - xk6 build --with github.com/grafana/xk6-output-prometheus-remote@latest
    - ./k6 run -o experimental-prometheus-rw --tag testid=test build/script.js
  artifacts:
    reports:
      junit: junit.xml
  when: manual

报错信息

go: downloading google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f
2023/07/19 12:50:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
2023/07/19 12:50:56 [INFO] Writing main module: /tmp/buildenv_2023-07-19-1250.1174414957/main.go
2023/07/19 12:50:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod edit -require go.k6.io/k6@0.44.1 
2023/07/19 12:50:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
go: errors parsing go.mod:
/tmp/buildenv_2023-07-19-1250.1174414957/go.mod:27:2: require go.k6.io/k6: version "0.44.1" invalid: unknown revision 0.44.1
2023/07/19 12:51:01 [INFO] Cleaning up temporary folder: /tmp/buildenv_2023-07-19-1250.1174414957
2023/07/19 12:51:01 [FATAL] exit status 1

解决方案

1. 指定明确的xk6和插件版本

避免使用@latest自动拉取可能存在版本兼容问题的组合,改用经过验证的稳定版本:

go install go.k6.io/xk6/cmd/xk6@v0.1.2
xk6 build --with github.com/grafana/xk6-output-prometheus-remote@v0.2.2

2. 强制指定k6版本构建

直接在xk6构建命令中指定官方存在的k6版本(例如当前稳定版v0.46.0),绕过自动版本匹配逻辑:

xk6 build v0.46.0 --with github.com/grafana/xk6-output-prometheus-remote@latest

3. 确保Go模块代理正常

在流水线变量中添加Go代理配置,保证模块能正确拉取:

variables:
  GOPROXY: "https://proxy.golang.org,direct"

修改后的完整作业配置示例

run:k6:
  stage: run
  environment: DEV
  variables:
    GIT_CHECKOUT: "false"
    GOPROXY: "https://proxy.golang.org,direct"
  image: golang:1.20
  needs:
    - job: build:k6
  script:
    - go install go.k6.io/xk6/cmd/xk6@v0.1.2
    - xk6 build v0.46.0 --with github.com/grafana/xk6-output-prometheus-remote@v0.2.2
    - ./k6 run -o experimental-prometheus-rw --tag testid=test build/script.js
  artifacts:
    reports:
      junit: junit.xml
  when: manual

内容的提问来源于stack exchange,提问作者Ravat Tailor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 16:33:12