Access environment variables from forge event callback

I have a Forge app that uses the trigger module to get callbacks when issues change. I’m trying to access a set environment variable from the function that’s run from one of these event triggers, and it’s consistently undefined.

My manifest.yml looks like this:

modules:
  trigger:
    - key: issue-update-trigger
      function: app-issue-events-func
      events:
        - avi:jira:updated:issue
  function:
    - key: main
      handler: index.run
    - key: app-issue-events-func
      handler: index.issueUpdate

I set the variable with:

forge variables set FORGE_USER_VAR_NAME value 

And my function looks like:

import * as process from 'process';

export async function issueUpdate(data) {
  const nameVar = process.env.FORGE_USER_VAR_NAME;
  console.log(nameVar);
  // undefined
}

Is it not possible to access environment variables from trigger functions?

The process object is available globally within Node.js and the Forge environment. Can you please try removing the process import - perhaps it is interfering with the one Forge provides?

1 Like

The proccess.env is available but it is not populated with any environment variables. There appears to be no documentation on how to read environment variables specified in the manifest at runtime.

Any help would be appreciated!

@JustinChase do you mind creating a new topic for this? Paste your app’s manifest and what you are doing as well so we can help you better.

I managed to figure it out the properties need to be set per environment, when we were running locally you just had the env vars set locally and since the manifest file lists the env vars so I thought it was pulling them at deploy time but I found out you need to run a seperate command to set the parameters.

I do think it would help a lot for the apps page to at the very least display the parameters set per environment, its really confusing that they’re hidden.