Use Task runner with custom environment variables

I’m using the latest version of n8n, v1.88.0, and I’m trying to adapt my workflows to use the task runner.

I’m using the default task runner configuration by just setting this environment variable:
N8N_RUNNERS_ENABLED=true

The problem is that the custom NPM package I use requires me to set some environment variables when it starts up. Everything was working normally, however, in this “sandbox” environment created by n8n, apparently the environment variables are not passed, which is a problem for me.

How can I solve this?

Haven’t tried this yet, but…

  1. The task runner env vars for n8n include a way to set NODE_OPTIONS.
  2. One of the nodeOptions allows specifying an env file.

See if that combination gets everything hooked up.

this is how i got it working:

FROM docker.n8n.io/n8nio/n8n:next AS base

USER root

# Add Kraken API environment variables
ARG KRAKEN_API_KEY=""
ENV KRAKEN_API_KEY=$KRAKEN_API_KEY

ARG KRAKEN_API_SECRET=""
ENV KRAKEN_API_SECRET=$KRAKEN_API_SECRET

RUN npm install -g remeda querystring axios ccxt ts-kraken

USER node

# Create .env file
RUN echo "KRAKEN_API_KEY=${KRAKEN_API_KEY}" > /home/node/.env
RUN echo "KRAKEN_API_SECRET=${KRAKEN_API_SECRET}" >> /home/node/.env
# n8n-values.yaml
imagePullSecret: "platform-5-ecr"
image:
  repository: "registry.digitalocean.com/platform-5-ecr/n8n"
  tag: "0.1.13"
resources:
  requests:
    memory: "1Gi"
  limits:
    memory: "2Gi"
n8n:
  extraEnv:
    - name: NODE_FUNCTION_ALLOW_BUILTIN
      value: "*"
    - name: NODE_FUNCTION_ALLOW_EXTERNAL
      value: "*"
    - name: NODE_OPTIONS
      value: "env-file=/home/node/.env"
    - name: N8N_RUNNERS_ALLOW_PROTOTYPE_MUTATION
      value: "true"

hope that helps :smiley:

1 Like

My environment variables cannot be in the Dockerfile. What would you suggest I do in this case?

1 Like