Unexpected executor invocation format

I’m trying to create an orb with a job to which an executor could be passed using parameters, but I’m getting an “Unexpected executor invocation format” error when running orb validate command.

I was able to achieve what I desired in a different way by passing tag as an executor argument in workflow, however, doing so requires to also specify the executor name in the workflow which I’d like to avoid as I would like default to be used.

I’ve created the following example orb that has the issue I’m facing:

version: 2.1

executors:
  php-executor:
    parameters:
      tag:
        type: string
        default: latest
    docker:
      - image: php:<< parameters.tag >>

jobs:
  build:
    parameters:
      executor:
        type: executor
        default: php-executor
      tag:
        type: string
        default: latest
    executor:
      name: << parameters.executor >>
      tag: << parameters.tag >>
    steps:
      - checkout

The full error message:

$ circleci orb --skip-update-check validate orb.yml 
Error: Error calling job: 'php-test'
Unexpected executor invocation format
The value of `name` must be a string
Examples of correct executor invocation:
  executor: string-executor-name
  executor: {name: string-executor-name}
  executor: << parameters.executor-type-parameter >>

:wave: Hello @martinssipenko, and welcome to the CircleCI Discuss community!

I believe the issue stems the use of executor --which is a reserved keyword-- as the parameter name.

Also, as stated in the other error message, the value given to name must be a string.

Furthermore, if you want to have the tag you specify as a job parameter passed to the executor parameter, and the into the reusable executor you declared, you’ll need to use “pass-through” parameters.

I suggest the following code:

version: 2.1

executors:
  php-executor:
    parameters:
      tag:
        type: string
        default: latest
    docker:
      - image: php:<< parameters.tag >>

jobs:
  build:
    parameters:
      my-executor:
        type: string
        default: php-executor
      version:
        type: string
        default: latest
    executor:
      name: <<parameters.my-executor>>
      tag: <<parameters.version>>
    steps:
      - checkout

Let me know if this helps.

Hello @yannCI , thank you for your answer.

I actually have tried the option you suggested before I opened this discussion, and it did not work for me.

When trying to validate the orb I’m getting the following error:

circleci orb --skip-update-check validate orb.yml
Error: Error calling job: 'build'
Cannot find a definition for executor named TEST_STRING

My orb.yaml file contents are:

version: 2.1

executors:
  php-executor:
    parameters:
      tag:
        type: string
        default: latest
    docker:
      - image: php:<< parameters.tag >>

jobs:
  build:
    parameters:
      my-executor:
        type: string
        default: php-executor
      version:
        type: string
        default: latest
    executor:
      name: <<parameters.my-executor>>
      tag: <<parameters.version>>
    steps:
      - checkout

Hi @martinssipenko,

The error you’re getting:

Cannot find a definition for executor named TEST_STRING

indicates that you’re trying to call the build job declared in your config as follows:

workflows:
  my-wkfw:
    jobs:
      - build:
          my-executor: TEST_STRING

There is no executor defined with the name TEST_STRING, hence the error you’re getting.

Here’s another example of a valid config.yml:

version: 2.1

executors:
  php-executor:
    parameters:
      tag:
        type: string
        default: latest
    docker:
      - image: php:<< parameters.tag >>

  ruby-executor:
    parameters:
      tag:
        type: string
        default: latest
    docker:
      - image: ruby:<< parameters.tag >>

jobs:
  build:
    parameters:
      my-executor:
        type: string
        default: php-executor
      version:
        type: string
        default: latest
    executor:
      name: <<parameters.my-executor>>
      tag: <<parameters.version>>
    steps:
      - checkout

workflows:
  my-wkfw:
    jobs:
      - build:
          name: Ruby build
          my-executor: ruby-executor

      - build:
          name: PHP build
          version: "8.0"

@yannCI I’m defining this executor in Orb where I do not have any workflows defined.

@yannCI I believe CiecleCI CLI does a GraphQL request to API for Orb validation that returns this error.

Hi, so what was the resolution to this? I’m getting the same error and there’s no “TEST-STRING” anywhere in my orb.yml file. Also, I’m getting this error when I run circleci orb publish and not when I’m executing any workflow.

1 Like

@martinssipenko did you manage to resolve this? I’m having the same issue

@martinssipenko How did you go about resolving this?

I am also getting Cannot find a definition for executor named TEST_STRING when I try to pass executor parameters in an orb.

Hey folks :wave:

If I understood correctly, you are trying to pass the executor name and the executor parameters as arguments to a job in an orb:

jobs:
  build:
    ...
    parameters:
      executor:
        type: executor
        default: php-executor
      tag:
        type: string
        default: latest
    executor:
      name: << parameters.executor >> # ❌ not supported
      tag: << parameters.tag >>

Unfortunately, we do not support this. When it comes to executors in an orb config, there are two approaches to follow:

A) Get the executor as a parameter

jobs:
  build:
    ...
    parameters:
      executor:
        type: executor
        default: php-executor
    executor: << parameters.executor >>

B) Hard-code the executor and get its parameters

jobs:
  build:
    ...
    parameters:
      tag:
        type: string
        default: latest
    executor:
      name: php-executor
      tag: << parameters.tag >>

B doesn’t offer a lot of flexibility. A, however, lets you receive the executor and its parameters as arguments. But as mentioned before, this occurs at the workflow level, outside the orb:

my-orb.yml:

version: 2.1
...
executors:
  php-executor:
    parameters:
      tag:
        type: string
        default: latest
    docker:
      - image: php:<< parameters.tag >>

jobs:
  build:
    parameters:
      executor:
        type: executor
        default: php-executor
    executor: << parameters.executor >>
    steps:
      - checkout

Notice how there is no tag parameter in the build job, but we can still pass it as an argument to the executor in the workflow:

.cicleci/config.yml:

version: 2.1

orbs: 
  my-orb: my-namespace/my-orb@1.0

workflows:
  build:
    jobs:
      - my-orb/build:
          executor: 
            name: php-executor
            tag: 7.2

Admittedly having the executor name as a parameter would make things easier, but it’s not possible at the moment. If you want to explore complex examples of the concept I shared above, I recommend looking at this orb. You can find its executors here, jobs here and a real-world example using it here.

I hope this helps!

2 Likes

This is gold. I easily would have wasted 2-3 days of my time trying to crack this.
Can we please update this in some of the official circleci documentation? Would be very very usesful.

Ways to pass executor as parameter

Thanks a lot Eric :bowing_woman:
You are a hero!