I have a command with an env_var_name parameter. The command has a step that uses a command that uses include() to wrap a script. I’m unsure of the syntax I am supposed to use in order to reference the value of that parameter from within the script since the include() wrapper seems to escape my double arrows <<
This is a decent work-around that should work in most cases. I have lengthy scripts I want to outsource to the scripts/ directory so I can shellcheck them, yet include them and evaluate parameters.
This is how I typically do it as well
I sometimes use an undescore prefix on the env var like _FOO: << parameters.foo >>
I think since the inline script gets rendered into the yaml as well, it will also “work” to directly use the mustache templating (i.e., reference << parameters.foo >>) in the script, except that it won’t be runnable / testable in there, and probably won’t pass shellcheck as @bjd2385 mentions.
I have lengthy scripts I want to outsource to the scripts/ directory so I can shellcheck them, yet include them and evaluate parameters.
Yeah, same thought process / reasoning for me.
I recently had a case where it was a super short script, and there, passing in the vars seemed too messy and like overkill, so ended up just inlining it in that case.
Heads up here. This can cause issues if you pass something in that isn’t an environment variable for instance. This will work just fine for you personally but we have run into issues trying to accommodate users who want strings and/or environment variables. If you pass in a literal string containing an equal sign for instance, it will break as it will interpret it as literal arithmetic.
If possible, you may want to use a tool like envsubst. I am currently putting a PR to the CLI to see what people thing about adding this tool directly to the build environment.