Run K6 tests in jenkins using docker image

I’m working on a Jenkins pipeline using the grafana/k6:0.57.0 Docker image, but I’m encountering an issue where commands within the container (e.g., ls, k6 version, etc.) are not executing when using the sh step. This setup used to work with the older loadimpact/k6 Docker image, where multiple tests could be triggered in the same container

podTemplate(label: LABEL, idleMinutes: 30,
  containers: [
      containerTemplate(name: 'k6-container', image: 'grafana/k6:0.57.0', command: 'cat', args: '', ttyEnabled: true ,alwaysPullImage: true)
    ]) {
      node(LABEL) {
        stage('Run Load Tests') {
          container('k6-container') {
            sh 'ls -al'
            sh 'k6 version'
            sh 'k6 cloud login --token TOKEN'
            sh 'k6 cloud script.js'
          }
        }
      }
    }

Has anyone else encountered this issue with the grafana/k6 image? How can I modify the pipeline to allow the execution of shell commands within the container? I would appreciate any insights or suggestions.

Hi @Shanmugavel-J , Welcome to hte community forum!

It will be beneficial if we knew what the error is and that it worked in k6 v0.56.0? By the looks of it nothing specific has changed in a while apart from bumps in version. :thinking:

Hi @Shanmugavel-J ,

I came across this issue with the same docker image grafana/k6:0.57.0 while trying to use k6 as a sidecar container within a jenkins-agent-pod because i am using jenkins deployed on kubernetes.

After further investigation, i noticed that:

  • the docker image grafana/k6:0.57.0 have the shell ash (alpine-shell) and not bash.
  • Jenkins-master is using bash
  • the pipeline i am using is calling the k6 tool using the ( sh ‘k6 run” ) and expecting to use bash and not ash
  • this incompatibility between shells is most likely the root cause of the issue

Solution:
simply build another docker image based on the grafana/k6:0.57.0 and add the bash to it:
FROM grafana/k6:0.57.0
USER root #without the root user you will encounter permission issues but after looking at the original dockerfile of the grafana/k6:0.57.0 in dockerhub, using the user k6 might also work
RUN apk add --no-cache bash

Hope I helped.