Skip to content

Provide step and work directories as context variables

Joe Burnett requested to merge jburnett/step-and-work-dirs into main

There are two important directories for steps to know about. One is the working directory for the step execution, which for runner will be set to CI_BUILDS_DIR. This is where all the "work" is happening. The second directory is the step definition directory in the cache where the step can find its auxiliary files.

Previously we were defaulting the exec dir to the step definition directory. This required every step to explicitly set work_dir to the working directory (builds directory).

This MR changes the default exec dir to be the working directory since this is the most simple usecase. For steps that need to find their files, a new context variable step_dir is provided. The global context variable work_dir is also set so steps can find their way back to where the work is.

I decided to make this change after implementing the first script step:

spec:
  inputs:
    script:
      type: string
---
env:
  SCRIPT: ${{ inputs.script }}
exec:
  work_dir: ${{ step_dir }}
  command: [ /usr/bin/env, bash, ./bash-exec.sh ]

It was really annoying before because I needed to take work_dir as an input and plumb it through. This is much easier. For steps that don't need anything from their definition dir, work_dir isn't even needed.

Edited by Joe Burnett

Merge request reports