K6 run in Azure DevOps using Docker is failing

Hi,

Intention is to run k6 inside an Azure DevOps pipeline using docker

k6 Docker is stored inside Artifactory : db-docker-utta-testautomation.artifactory.abcdef/loadimpact:v0.44.1

I was successful to run, inside the pipeline, after writing following command inside yml file

" - script: docker run --rm -i
               db-docker-utta-testautomation.artifactory.abcdef/loadimpact:v0.44.1 
              run -<./K6PerformanceTesting/script.js"

BUT
to get the output stored inside a json file getting error

My code

" - script: docker run -i --rm 
                      -v /K6PerformanceTesting/:/K6PerformanceTesting/
                      -v /k6Report/:/k6Report/
                      db-docker-utta-testautomation.artifactory.abcdef/loadimpact:v0.44.1 
                      run --out json=/k6Report/my_test_result.json /K6PerformanceTesting/script.js"

Error:

time="2023-05-29T09:14:47Z" level=error msg="The moduleSpecifier \"/K6PerformanceTesting/script.js\" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see [https://k6.io/docs/using-k6/modules#using-local-modules-with-docker."](https://k6.io/docs/using-k6/modules#using-local-modules-with-docker.%22)

##[error]Bash exited with code '255'.

Folder structure is correct
image

Hi @Subho

Based on the error, the script is not found in your path.

The moduleSpecifier \"/K6PerformanceTesting/script.js\" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container.

And it points you to the docs to solve this: Modules, and we have an excellent example of the docker command in JSON.

This is a docker issue, more than a k6 one, and I as suche I’d recommend having a look at the docker documentation regarding mounting volumes: Bind mounts | Docker Documentation

I find this works if I try to execute something similar with docker locally. It’s a matter of correctly indicating where the scripts and output will be.

docker run --rm -i -v "$PWD:/K6PerformanceTesting" -v "$PWD:/k6Report"  grafana/k6 run --vus 10 --duration 5s --out json=/k6Report/out.json /K6PerformanceTesting/script.js

This creates an out.json in the ./k6Report directory (if it has write permissions), and also reads the script.js from ./K6PerformanceTesting.

Once it works for you locally, this will probably also work on Azure DevOps. However, I did not test it.

I hope this helps.

Cheers!

Thanks it worked :slight_smile:
docker run -i --rm
-v $PWD/utils:/utils
-v $PWD/k6Report:/k6Report
db-docker-utta-testautomation.artifactory.abcdef/loadimpact:v0.44.1
run -<./K6PerformanceTesting/junitscript.js
–summary-export=/k6Report/junit.xml

it also generated an xml

1 Like