From db693fbecc8f9bac9ff91b58e8e1b1f85fa98bd6 Mon Sep 17 00:00:00 2001 From: Ani Date: Fri, 24 Apr 2026 11:38:13 +0300 Subject: [PATCH] fix(workflows): export ARTIFACTS_DIR, LOG_DIR, BASE_BRANCH to bash nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit executeBashNode previously only merged explicit envVars on top of process.env. The three well-known workflow directories (artifactsDir, logDir, baseBranch) were passed as function parameters and used for compile-time substitution of $ARTIFACTS_DIR / $LOG_DIR / $BASE_BRANCH in the script body, but were never added to the subprocess environment. As a result, any script that relied on shell-runtime expansion — e.g. JSON_FILE="${ARTIFACTS_DIR}/foo.output.json" inside a heredoc, an inherited helper script, or a `bash -c` subshell — saw the variable unset and silently fell back to its default (typically an empty string or "."), writing artifacts to the workflow cwd instead of the nominal artifacts directory. Always build subprocessEnv from process.env plus the three well-known directories, then allow explicit envVars to override. Compile-time substitution behavior is unchanged; existing scripts that do not reference these variables are unaffected; user-supplied envVars still win on conflict. --- packages/workflows/src/dag-executor.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/workflows/src/dag-executor.ts b/packages/workflows/src/dag-executor.ts index 63e4d6cafd..7937eec22f 100644 --- a/packages/workflows/src/dag-executor.ts +++ b/packages/workflows/src/dag-executor.ts @@ -1137,8 +1137,13 @@ async function executeBashNode( const finalScript = substituteNodeOutputRefs(substitutedScript, nodeOutputs, true); const timeout = node.timeout ?? SUBPROCESS_DEFAULT_TIMEOUT; - const subprocessEnv = - envVars && Object.keys(envVars).length > 0 ? { ...process.env, ...envVars } : undefined; + const subprocessEnv: NodeJS.ProcessEnv = { + ...process.env, + ARTIFACTS_DIR: artifactsDir, + LOG_DIR: logDir, + BASE_BRANCH: baseBranch, + ...(envVars ?? {}), + }; try { const { stdout, stderr } = await execFileAsync('bash', ['-c', finalScript], {