Skip to content

Commit

Permalink
✨ v1.1 new env var feature
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-uk committed Mar 30, 2021
1 parent f4429d8 commit 5a87b71
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Everything

## [1.1.0] - 2021-30-03

### Added

- Support for setting vars at runtime using `POSTMAN_{var}`
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ The dashboard can be found in the [grafana directory](https://github.com/benc-uk
| ENABLE_BAIL | Stops the run when a test case or request fails | false |
| ENABLE_REQUEST_METRICS | Disable the per-request metrics if you wish | true |
| ENVIRONMENT_FILE | Path to a Postman environment file | _none_ |
| POSTMAN\_{varname} | Environment vars to pass to running the collection | _none_ |

## Note on Postman variables

Postman/Newman can [accept variables a number of ways](https://learning.postman.com/docs/sending-requests/variables/) with this runner you supply values for any variables your scripts reference in two ways:

- Environments file, created by defining an environment in Postman and [exporting as JSON](https://learning.postman.com/docs/getting-started/importing-and-exporting-data/#exporting-environments)
- Using special `POSTMAN_{varname}` environment vars, set as regular OS environment vars (therefor settable at runtime from Docker and Kubernetes). The prefix `POSTMAN_` is required and stripped off, leaving the name of the variable to set when running the collection, e.g. if your Postman request referenced a variable `{{myvar}}` you can set it using `POSTMAN_myvar=foo`

# Repo Contents

Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postman-prometheus",
"version": "1.0.0",
"version": "1.1.0",
"description": "Run Postman collections continuously and export results as Prometheus metrics",
"main": "server.js",
"author": "Ben Coleman",
Expand Down
14 changes: 14 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,26 @@ app.listen(port, async () => {

function runCollection() {
logMessage(`Starting run of ${collectionFile}`)

// Special logic to bring all env vars starting with POSTMAN_ into the run
let postmanEnvVar = []
for (let envVar in process.env) {
if (envVar.startsWith('POSTMAN_')) {
postmanEnvVar.push({
// Remove the prefix
key: envVar.replace('POSTMAN_', ''),
value: process.env[envVar],
})
}
}

newman.run(
{
collection: require(collectionFile),
iterationCount: parseInt(runIterations),
bail: enableBail == 'true',
environment: envFile,
envVar: postmanEnvVar,
},
runComplete
)
Expand Down

0 comments on commit 5a87b71

Please sign in to comment.