What’s the canonical way to allow setting env vars in an orb? Just having a passthrough parameter? Anyone have a good example of this? Alternately, I guess I could override environment for the executor instead?
Correct, there’s not a great way to do this @wyardley.
If you’re making the orb, and you anticipate folks will want to pass a lot of environment variables, then you might make a passthrough parameter. That said, since we don’t currently provide a list type, or any built-in looping functionality, etc., it would be hard to make it work for multiple environment variables without creating a single parameter for each one, which isn’t ideal.
It’s worth mentioning that run steps also take environment variables, so if there’s a particular thing you want to use them for in your job, you can always use pre-steps and post-steps and set the environment variables on a run step there.
That said, if the environment variables are needed for the actual orb logic being carried out by the job, then I’d say that suggests the job should already have the requisite parameters for folks to pass it whatever environment variables it will need.
I’ll test this out, but I’m assuming the latter?
The other problem I’m having is that I want to set an env var to the string ‘True’ but only if a param is set with a boolean true. Seems like that may not be possible?
Neither. A job has a single executor. It would look like this:
So if I want to override a param for an executor, I have to do it for each job, vs. at top level?
Sure, you can do this with Mustache templating.
That works perfect more or less as in your example for my use case.
Question: Can that templating only be used in values, or could I use the Mustache templating to suppress the field from existing entirely (conditionally)? Are there any more docs about using Mustache templating inside orbs? A quick search didn’t turn up too much.
So, I guess I would have expected that since executors are parameterized, that I could set that parameter for all instances of an executor. Let’s say I have an executor named ‘node’ (e.g., https://circleci.com/orbs/registry/orb/honeyscience/node ) – I might want to set the version of node used for all jobs using that executor. I guess this would have been trying to get around the fact that you can’t set top level parameters for orbs themselves.
Not really, that’s why defaults exist though. Ideally, you set sensible defaults for your executors’ parameters, and then don’t have to pass them different values particularly often. And you can always use YAML anchors to avoid repeating things.