Using Gitlab variable with newman

Hi, I setup newman to run my collections in gitlab pipeline. I wanted to allow the user to set a value for a Gitlab environement variable before running my newman test pipeline. I am wondering is there a possible way for newman to inject a gitlab variable and his value into the environment.json?

Thanks.

Hey @mikeccc

Welcome to the community! :trophy:

Depending on how you’re using Newman in your pipeline - You can add those Gitlab variables into the Collection like this?

From the CLI:

--env-var "variable_name=$GITLAB_VAR"

Newman as a library:

    envVar: [ 
        { "key":"variable_name", "value": $GITLAB_VAR}
    ]

If you wanted to share your pipeline file, I could give you a better/more focussed solution.

Thanks a lot @danny-dainton . I’ll give it a try. Thanks for the advice.
Truly appreciated.

1 Like

Hi @danny-dainton ,

I tried this but It wont work for me.

1.Created one CICD variable name as Access_Token.

2.Given variable in environment file like following -
{
“key”: “Access_Token”,
“value”: ​$Access_Token​
}

3.using following newman command -
newman run APIQATEST.json -e APIQATEST_environment.json --env-var “Access_Token=$Access_Token” --reporters cli,htmlextra --reporter-htmlextra-export report.html

I got error as -
error: could not load environment

No value found for key value at 67:13

“value”: ​$Access_Token​

Could you please let me know anything which I missed.

Best Regards,
Sri

If you have the placeholder {{Access_Token}} in your Collection already, you don’t need to use an environment file with the command as it would resolve that to the value set in the --env-var flag.

Each CI tool has its own syntax it uses for variables and most are only uppercase - I’d be surprised it your one would work but you could also try echoing out the variable in the CI Tools console to ensure it’s resolving it correctly.

1 Like

Hi @danny-dainton ,

Thank You so much for quick reply. I just tried your suggested solution. It works for me.
Much Appreciated.

Best Regards,
Sristi

1 Like