Skip to content

bug: can't pass a secret to Slack alert channel from an env file #1137

@ducatore

Description

@ducatore

Node.js version

all

NPM version

all

@checkly/cli version

6.4.0

Steps to reproduce

Create a Slack alert channel and use an env var to get the the webhook url

export const slackChannel = new SlackAlertChannel('slack-channel-1', {
  url: new URL(process.env.WEBHOOK_URL_SECRET),
  channel: '#ops',
  ...sendDefaults
})

Execute the test using an env file:

npx checkly test --env-file=.env

Outpu

Parsing your project... !
    Error: Error loading file '/tmp/debug-checkly/__checks__/resources/alert-c
    hannels/slack/alert-checkly-dev.check.ts'
    TypeError: Invalid URL
        at new URL (node:internal/url:826:25)
        at /tmp/debug-checkly/__checks__/resources/alert-channels/slack/alert-
    checkly-dev.check.ts:5:8
        at async Function.import 
    (/tmp/debug-checkly/node_modules/jiti/dist/jiti.cjs:1:202945)
        at async InitializedJitiFileLoaderState.loadFile 
    (/tmp/debug-checkly/node_modules/checkly/dist/loader/jiti.js:45:31)
        at async JitiFileLoader.loadFile 
    (/tmp/debug-checkly/node_modules/checkly/dist/loader/jiti.js:59:16)
        at async MixedFileLoader.loadFile 
    (/tmp/debug-checkly/node_modules/checkly/dist/loader/mixed.js:23:28)
        at async Session.loadFile (/tmp/debug-checkly/node_modules/checkly/dis
    t/constructs/project.js:184:35)
        at async loadAllCheckFiles (/tmp/debug-checkly/node_modules/checkly/di
    st/services/project-parser.js:117:13)
        at async parseProject (/tmp/debug-checkly/node_modules/checkly/dist/se
    rvices/project-parser.js:54:5)
        at async Test.run 
    (/tmp/debug-checkly/node_modules/checkly/dist/commands/test.js:157:25)

What is expected?

process.env.WEBHOOK_URL_SECRET contains the secret and I can use it to set the webhook url

What is actually happening?

The env var loaded from a file seems to be only available later but not when the Slack alert channel is instantiated.
It works passing the env var through the command line

WEBHOOK_URL_SECRET=http://example.com npx checkly test

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    tbdTo be discussed with stakeholders.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions