pentaho/pentaho-kettle · error · KettleJobException

JobEntrySetVariables.Error.UnableSetVariableCurrentJob

Error message

JobEntrySetVariables.Error.UnableSetVariableCurrentJob

What it means

This KettleJobException is thrown in execute() when the variable scope is 'set variable in the current job' (VARIABLE_TYPE_ROOT_JOB) but no parent Job is available to set the variable on. The entry can only apply the variable when it is running inside a Job; when the context is missing (e.g. run in a way that provides no parent job) it aborts with the variable name in the message.

Solutions

  1. Run the entry inside a Job (not standalone/in a transformation) so parentJob is available
  2. Choose a different variable scope, e.g. 'Valid in the Java API' or 'Valid in the parent job', matching your execution context
  3. If invoking from code, set the entry's parent job via setParentJob(job) before execute()
  4. At runtime in production, ensure the job is launched through the normal Job executor (Kitchen/Spoon) rather than partial test paths

Example fix

// before (custom harness)
JobEntrySetVariables entry = new JobEntrySetVariables();
Result r = entry.execute(new Result(), 1); // parentJob == null -> throws
// after
entry.setParentJob(job);
Result r = entry.execute(new Result(), 1);
Defensive patterns

Strategy: validation

Validate before calling

// verify scope fits the execution context before running
if ("ROOT_JOB".equals(scope) && job.getParentJob() == null) {
  // entry is not running inside a Job; pick another scope or fix the runner
  throw new IllegalStateException("Set Variables entry requires a parent Job for root-job scope");
}

Try / catch

try {
  result = jobEntry.execute(result, nr);
} catch (KettleJobException e) {
  if (e.getMessage().contains("UnableSetVariableCurrentJob")) {
    logError("No parent job in context; run inside a Job or use another variable scope");
  }
}

Prevention

When it happens

Trigger: Setting variable type 'Valid in the root job' while parentJob is null - e.g. the entry is executed outside a proper Job context (standalone/debug execution, or run from a transformation/test harness that does not supply a parent Job).

Common situations: Testing the job entry standalone in Spoon where the root-job context isn't wired; entry used in a transformation instead of a job; custom Java harness invoking execute() directly without parentJob.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/025d5491dc5f6da5. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/job/entries/setvariables/JobEntrySetVariables.java:328

          case VARIABLE_TYPE_CURRENT_JOB:
            setVariable( varname, value );

            if ( parentJob != null ) {
              String parameterValue = parentJob.getParameterValue( varname );
              // if not a parameter, set the value
              if ( parameterValue == null  ) {
                setEntryStepSetVariable( varname, value );
              } else {
                //if parameter, save the initial parameter value for use in reset/clear variables in future calls
                if ( parameterValue != null && parameterValue != value && !entryStepSetVariablesMap.containsKey( varname ) ) {
                  setEntryStepSetVariable( varname, parameterValue );
                }
              }
              parentJob.setVariable( varname, value );

            } else {
              throw new KettleJobException( BaseMessages.getString(
                PKG, "JobEntrySetVariables.Error.UnableSetVariableCurrentJob", varname ) );
            }
            break;

          case VARIABLE_TYPE_PARENT_JOB:
            setVariable( varname, value );

            if ( parentJob != null ) {
              parentJob.setVariable( varname, value );
              Job gpJob = parentJob.getParentJob();
              if ( gpJob != null ) {
                gpJob.setVariable( varname, value );
              } else {
                throw new KettleJobException( BaseMessages.getString(
                  PKG, "JobEntrySetVariables.Error.UnableSetVariableParentJob", varname ) );
              }
            } else {
              throw new KettleJobException( BaseMessages.getString(

View on GitHub (pinned to f3058517a1)