{"id":13342889,"url":"https://github.com/oleiade/xk6-exec","last_synced_at":"2025-04-13T12:44:59.560Z","repository":{"id":218649425,"uuid":"640825504","full_name":"oleiade/xk6-exec","owner":"oleiade","description":"A k6 extension to execute shell commands from your k6 scripts","archived":false,"fork":false,"pushed_at":"2023-05-15T08:00:57.000Z","size":28,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T21:53:52.848Z","etag":null,"topics":["exec","extension","k6","performance-testing","shell","xk6"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oleiade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-15T07:54:51.000Z","updated_at":"2024-10-28T14:31:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"ab5a8433-ed46-4d23-b173-6b7f7e185e64","html_url":"https://github.com/oleiade/xk6-exec","commit_stats":null,"previous_names":["oleiade/xk6-exec"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Fxk6-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Fxk6-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Fxk6-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Fxk6-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oleiade","download_url":"https://codeload.github.com/oleiade/xk6-exec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717241,"owners_count":21150387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exec","extension","k6","performance-testing","shell","xk6"],"created_at":"2024-07-29T19:30:06.640Z","updated_at":"2025-04-13T12:44:59.528Z","avatar_url":"https://github.com/oleiade.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# k6 Extension - Exec\n\nThis extension for k6 allows you to execute shell commands from your k6 scripts.\nIt exposes a new global object `Cmd` in the k6 JavaScript context, which can be used to construct commands.\n\n## Installation\n\nFirst, you need to install [xk6](https://github.com/k6io/xk6) and then build the k6 binary with the exec extension.\n\nTo install xk6, run:\n\n```bash\ngo install github.com/grafana/xk6/cmd/xk6@latest\n```\n\nThen build the k6 binary:\n\n```bash\nxk6 build --with github.com/oleiade/xk6-exec@latest\n```\n\nThis will result in a `k6` binary in the current directory.\n\n## Usage\n\nAfter you've built the `k6` binary, you can use it to run your scripts that use the `exec` extension. Here's a simple example:\n\n```javascript\nimport { check } from \"k6\";\nimport { Cmd } from \"k6/x/cmd\";\n\nexport default async function () {\n  // Produce the command you wish to run\n  // using the composable API.\n  const cmd = new Cmd(\"motus\")\n    .arg(\"memorable\")\n    .arg(\"--words\")\n    .arg(\"12\")\n    .env(\"NO_COLOR\", \"true\");\n\n  // Execute the command and wait for it to finish.\n  const result = await cmd.exec();\n\n  // Check the result of the command.\n  check(result, {\n    \"exit code is 0\": (r) =\u003e r.exitCode === 0,\n    \"stdout contains 12 words\": (r) =\u003e r.stdout.split(\" \").length === 12,\n  });\n}\n```\n\nIn the above script, we're creating a new `Cmd` object with the command `motus`. We add arguments to the command using the `Arg` method. We add environment variables using the `Env` method. Then we execute the command with the `Exec` method, which returns a promise that resolves with the command's result.\n\n## Metrics\n\nThe exec extension also provides custom k6 metrics:\n\n- `exec_command_duration`: The duration of the command execution.\n- `exec_commands_total`: The total number of executed commands.\n- `exec_command_stdout_bytes`: The total number of bytes written to stdout by the command.\n- `exec_command_stderr_bytes`: The total number of bytes written to stderr by the command.\n- `exec_command_failed_rate`: The rate of command executions that failed.\n\nThese metrics are exposed to k6 and will appear in the summary at the end of a k6 test execution.\n\n## Caution\n\nThis extension is potentially unsafe as it allows scripts to execute arbitrary commands on the system running k6. Use it responsibly and avoid running untrusted scripts.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleiade%2Fxk6-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foleiade%2Fxk6-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleiade%2Fxk6-exec/lists"}