Automation - make variable substitution work anywhere in yaml
See original GitHub issueIs your feature request related to a problem? Please describe.
I have tried to use (env) variables in my YAML file for the automation framework, but it looks like variables only work in the env.ctx
section of that YAML.
Describe the solution you’d like
It would be nice if I could write a YAML file like so:
env:
contexts:
# .. my context
jobs:
- type: "openapi"
parameters:
apiFile: ${OPENAPI_FILE}
Additionally, using variables defined in env.vars
should be usable across the configuration as well:
env:
contexts:
# .. my context
vars:
myApiFile: openapi.json
jobs:
- type: "openapi"
parameters:
apiFile: ${myApiFile}
Describe alternatives you’ve considered
I have also tried pulling in the environment variables via env.parameters.vars
, like so:
env:
contexts:
# .. my context
vars:
openapiFile: ${OPENAPI_FILE}
jobs:
- type: "openapi"
parameters:
apiFile: ${openapiFile}
Screenshots
No response
Additional context
- When I use a variable that does not exist somewhere in the
env.contexts
, I get an error saying “Variable myVariable used but not specified”, but when I try${myVariable}
in thejobs
section, it’s justnull
- I looked at the PR that implemented variable substitution for the automation framework (https://github.com/zaproxy/zap-extensions/pull/2883) and it looks pretty clear to me that this only works for the
env
section. - However that PR also contains some docs, like this line:
vars: # List of 1 or more variables, can be used throughout the config
. This seems to suggest that variables can be used throughout the config.
Would you like to help fix this issue?
- Yes
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Substituting variable values | Cloud Build Documentation
Substitutions are helpful for variables whose value isn't known until build time, or to re-use an existing build request with different variable values....
Read more >Can we do variable substitution on YAML files in IntelliJ?
I don't see such feature in IDEA. I would recommend you to use git stash to save a modified version for these config...
Read more >File transforms and variable substitution - Azure Pipelines
Variable substitution is applied for only the JSON keys predefined in the object hierarchy. It does not create new keys. If a variable...
Read more >Understanding Azure DevOps Variables [Complete Guide]
Pipeline variables are referenced in the YAML build definitions and can be referenced via three different syntax methods – macro, template ...
Read more >Jinja2 Tutorial - Part 1 - Introduction and variable substitution |
How does it work? Jinja templating basics. Variable substitution; Examples. Python example; Ansible example. Dictionaries as variables ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Results in:
@rethab great! I’m assigned this issue to you. We do have a load of docs eg https://www.zaproxy.org/docs/contribute/coding/ I’ve labelled this as a ‘good first issue’ as there are already examples in the code of how to do this, but if you need any pointers then just say. We do need unit tests for all PRs but again, if you need any advice and guidance for that then just say. You dont have to fix everything in your first PR - just fixing one instance would be fine and a good way to get used to our proceedures 😃