Good evening,
I have a postman environment variable as a json file pushed to github action. This environment variable contains an api key which is hardcoded. To resolve this I added the api key in github action secrets. In the YAML file I am running newman with collections and environments. I am struggling to understand how it can be passed to my collection so my apis can pass. Need advice from this community as I am new to postman and github.
Postman Environment variable : Test-env.postman_environment.json
{
"key": "ApiKey",
"value": "abcdefg",
"type": "secret",
"enabled": true
},
In the header of my API, i am passing this APIkey
{
"key": "Api-Key",
"value": "{{ApiKey}}"
},
In order to avoid hardcoding of api key “abcdefg” in environment variable. I decided to add it in githubsecrets.
In githubaction, added the value “abcdefg” as “test” in secrets
My yaml file is like this
name: Test secrets
on:
push:
workflow_dispatch:
jobs:
Test-api:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# INstall Node on the runner
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "20.x"
# Install the newman command line utility and also install the html extra reporter
- name: Install newman
run: |
npm install -g newman
npm install -g newman-reporter-htmlextra
# Run the POSTMAN collection
- name: Run POSTMAN collection
run: |
run: |
newman run "Testapi.postman_collection.json" -e "Test-env.postman_environment.json" -r cli,htmlextra --reporter-htmlextra-showEnvironmentData --reporter-htmlextra-export Reports/reports.html
# Upload the contents of Test Results directory to workspace
- name: Output the run Details
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: Report - Test
path: Reports/Terstreports.html
retention-days: 20