List parameter type?

I’m new to orbs, and started playing around with creating an orb for one of my tools.

One of the parameters I want to take as input can be specified multiple times, but there doesn’t seem to be an appropriate parameter type for this, according to https://circleci.com/docs/2.0/reusing-config/#parameter-types.

In the meantime, I can use a comma-separated string, but this is a bit non-obvious and will be slightly more difficult to deal with.

Is a list parameter type planned? Or is there some undocumented support already?

1 Like

We don’t yet have a generic list or collection type. One issue is that we have been hesitant to put looping constructs directly in our yaml for fear of creating a yaml-based programming language. That said, it’s clear that some way to pass multiple values would be useful, so it’s something we have on our list of improvements. Curious: how would you envision the syntax looking when you use a list? We could potentially pass it through serialized for use in shell commands, but that is a bit messier than we’d like.

2 Likes

Thanks for the quick response, @ndintenfass

I’m used to dealing with the Go text/template package, in fact, the tool I’m trying to Orb-ify is https://github.com/hairyhenderson/gomplate, which is a template renderer that uses the text/template syntax.

So I’d imagine a syntax like this:

commands:
  foo:
    parameters:
      alist:
        type: list
    steps:
      - run: |
          << range parameters.alist >>echo "param is << . >>";<< end >>
jobs:
  - foo_job:
      - myorb/foo:
          alist:
            - first
            - second

This would output:

param is first
param is second

This is just off the top of my head, and probably isn’t as intuitive to folks who aren’t familiar with the text/template syntax!

Thanks,
-Dave

I only mention this because of the specific example you used here @hairyhenderson, because I know this isn’t quite what you’re looking for in a broader sense, but you can use the steps parameter type to allow folks to pass a list/collection—as long as it’s a list of steps. Which would get you to your example, although it’s not quite as DRY as what you’ve outlined here.

Thanks @rose - that looks like an interesting hack - I didn’t realize steps could be used that way…

But you’re right, it’s not quite what I’m looking for… :wink:

I’ll play around with it and see if it’s enough for now.

1 Like

I can contribute another use case. I would like this to support passing multiple paths to the paths key of save_cache.

with_cache:
    parameters:
      key:
        type: string
      namespace:
        type: string
      steps:
        type: steps
      path:
        type: string # actually want a list type here
      strict:
        type: boolean
        default: false
      branch_sensitive:
        type: boolean
        default: true
    steps:
      - when:
          condition: <<parameters.strict>>
          steps:
            - when:
                condition: <<parameters.branch_sensitive>>
                steps:
                  - restore_cache:
                      keys:
                        - orb-v1-project-v{{ .Environment.CACHE_VERSION }}-<<parameters.namespace>>-{{ .Branch }}-<<parameters.key>>
            - unless:
                condition: <<parameters.branch_sensitive>>
                steps:
                  - restore_cache:
                      keys:
                        - orb-v1-project-v{{ .Environment.CACHE_VERSION }}-<<parameters.namespace>>-<<parameters.key>>

      - unless:
          condition: <<parameters.strict>>
          steps:
            - when:
                condition: <<parameters.branch_sensitive>>
                steps:
                  - restore_cache:
                      keys:
                        - orb-v1-project-v{{ .Environment.CACHE_VERSION }}-<<parameters.namespace>>-{{ .Branch }}-<<parameters.key>>
                        - orb-v1-project-v{{ .Environment.CACHE_VERSION }}-<<parameters.namespace>>-{{ .Branch }}-
                        - orb-v1-project-v{{ .Environment.CACHE_VERSION }}-<<parameters.namespace>>-
            - unless:
                condition: <<parameters.branch_sensitive>>
                steps:
                  - restore_cache:
                      keys:
                        - orb-v1-project-v{{ .Environment.CACHE_VERSION }}-<<parameters.namespace>>-<<parameters.key>>
                        - orb-v1-project-v{{ .Environment.CACHE_VERSION }}-<<parameters.namespace>>-
      - steps: <<parameters.steps>>
      - save_cache:
          key: orb-v1-project-v{{ .Environment.CACHE_VERSION }}-<<parameters.namespace>><<# branch_sensitive >>-{{ .Branch }}<</ branch_sensitive >>-<<parameters.key>>
          paths:
            - <<parameters.path>>  # actually want a list type here
1 Like

Thanks @jasonkuhrt—I also want this! :smile:

Can you (or anyone else on the thread) create an idea in our Ideas Portal (if one doesn’t exist already) so we can formally track it as a feature request?

Looks like there is already this https://ideas.circleci.com/ideas/CCI-I-701

2 Likes

Yup - I already created one back in November when I originally posted this: https://ideas.circleci.com/ideas/CCI-I-701

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.