Cannot build custom orb that depends on slack-orb

When building a custom orb that uses slack-orb, the orb-tools/pack job fails with:

#!/bin/bash -eo pipefail
#!/bin/bash
# NOTE: an explicit API token is required for orb validation, for self-hosted CircleCI.
# In the case of CircleCI cloud (https://circleci.com), an API token is not needed.

ORB_DIR=${ORB_VAL_ORB_DIR%/}
ORB_FILE=${ORB_VAL_ORB_FILE_NAME#/}


if [ "https://circleci.com" != "${ORB_VAL_CIRCLECI_API_HOST}" ] && [ -z "${CIRCLE_TOKEN}" ]; then
    echo "Please set a valid CIRCLE_TOKEN token from your self-hosted CircleCI."
    exit 1
fi

circleci orb validate --host "${ORB_VAL_CIRCLECI_API_HOST:-https://circleci.com}" --token "${CIRCLE_TOKEN:-dummy}" ${ORB_VAL_ORG_ID:+--org-id "$ORB_VAL_ORG_ID"} ${ORB_VAL_ORG_SLUG:+--org-slug "$ORB_VAL_ORG_SLUG"} --skip-update-check "${ORB_DIR}/${ORB_FILE}"

Error: Error calling command: ‘release_notify_slack’
Error calling command: ‘slack/notify’
Type error for argument event: expected type: enum (“fail” “pass” “always”), actual value: “TEST_STRING” (type string)

Exited with code exit status 255

CircleCI received exit code 255

release_notify_slack is my custom command that uses slack/notify.

I’m using latest slack-orb (4.12.5) and latest 2 major versions of orb-tools (11.5, 12.0).

Honestly, this feels more like a bug in how circleci orb validate handles enum parameters
TEST_STRING seems to be coming from the circleci orb validate run in app.circleci.com.
I cannot reproduce locally with circleci org validate, via brew (version 0.1.26837+b104265 (homebrew)) or docker (image circleci/circleci-cli:0.1.26646).

I found at least one third-party orb that actively works around this problem with enums via an unfortunate hack: github(dot)com/LedgerHQ/circleci-orbs/blob/ed2095079f737308d82fa8515cc2096865862af0/src/chef/orb.yml#L169-L170
Though they did this 3 years ago, so this doesn’t seem to be a new thing?

Is there a better workaround known, or should I file an issue somewhere?

Solved it.

First, my reproduce steps were wrong.
I needed to circleci orb pack to get the single-file orb to and then validate that single file:

$ circleci orb validate <(circleci orb pack src)

Error: Error calling command: 'release_notify_slack'
Error calling command: 'slack/notify'
Type error for argument event: expected type: enum ("fail" "pass" "always"), actual value: "TEST_STRING" (type string)

With that reproducer, I was able to figure out the problem.

I was forwarding the “event” parameter from my custom release_notify_slack command to slack/notify like:

# release_notify_slack.yml

parameters:
  event:
    type: "string"
    default: "always"

steps:
    - slack/notify:
        event: "<< parameters.event >>"
        ...

Note that event is an enum parameter on slack/notify, but I was taking it as a string parameter.
So the problem was effectively a type mismatch between string and enum.

I switched my event parameter to be the same enum as slack/notify and it now works!

1 Like

Thanks for the writeup @PhilMarsh! Glad you were able to resolve the issue and share with us your findings.

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