Kubernetes executor does not apply step environment variables #2974
Dominik opened 1 day ago

Environment variables defined on a CommandStep under envVars are not present in the container when the job runs on a KubernetesExecutor. The same buildspec works on a RemoteDockerExecutor.

Versions: OneDev 16.4.1, k8s-helper 4.2.0, k3s v1.35.5.

Reproduce:

  1. Job with one CommandStep, runInContainer: true, image python:3.12-alpine, envVars: [{name: FOO, value: bar}], command echo "FOO=$FOO".
  2. Run it on a KubernetesExecutor.

Expected: FOO=bar Actual: FOO=

The server does send the variable to the pod. /onedev-build/job-data inside the build pod contains the name and value but nothing applies it:

  • every container in the job pod has exactly three env entries: ONEDEV_SERVER_URL, ONEDEV_JOB_TOKEN, ONEDEV_WORKDIR
  • the generated /onedev-build/command/<step>.sh contains no export

In KubernetesExecutor each container spec is built with

    "env", SerializationUtils.clone(commonEnvs)

and commonEnvs only ever holds those three entries; the step's env vars are never merged in.

Impact: any job secret passed through envVars arrives empty, so steps fail in confusing ways (an empty SSH key gives Load key: error in libcrypto followed by Permission denied (publickey)), and deployment jobs can run with empty credentials rather than failing outright.

Workaround: export the variables inline at the top of the command text, where @secret:...@ interpolation still works.

1/1
Type
Bug
Priority
Major
Assignee
Affected Versions
16.4.1
Labels
No labels
Issue Votes (0)
Watchers (3)
Reference
OD-2974
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover