Search code examples
bashvariablesrundeck

Rundeck sharing variables across job steps


I want to share a variable across rundeck job steps.

  1. Initialized a job option "target_files"
  2. Set the variable on STEP 1.

    RD_OPTION_TARGET_FILES=some bash command
    echo $RD_OPTION_TARGET_FILES
    The value is printed here.

  3. Read the variable from STEP 2.
    echo $RD_OPTION_TARGET_FILES

Step 3 doesn't recognize the variable set in STEP 1.
What's a good way of doing this on rundeck other than using environment variables?


Solution

  • The detailed procedure from RUNDECK 2.9+:

    1) set the values - three methods:

    1.a) use a "global variable" workflow step type e.g. fill in: Group:="export", Name:="varOne", Value:="hello"

    1.b) add to the workflow a "global log filter" (the Data Capture Plugin cited by 'Amos' here) which takes a regular expression that is evaluated on job step log outputs. For instance with a job step command like:

       echo "CaptureThis:varTwo=world"
    

    and a global log filter pattern like:

       "CaptureThis:(.*?)=(.*)" 
    

    ('Name Data' field not needed unless you supply a single capturing group in the pattern)

    1.c) use a workflow Data Step to define multiple variables explicitly. Example contents:

    varThree=foo
    varFour=bar
    

    2) get the values back:

    you must use the syntax ${ctx.name} in command strings and args, and @ctx.name@ within INLINE scripts. In our example, with a job step command or inline script line like:

    echo "values : @export.varOne@, @data.varTwo@, @stub.varThree@, @stub.varFour@"
    

    you'll echo the four values.

    The context is implicitly 'data' for method 1.b and 'stub' for method 1.c.

    Note that a data step is quite limitative! It only allows to benefit from @stub.name@ notations within inline scripts. Value substitution is not performed in remote files, and notations like ${stub.name} are not available in job step command strings or arguments.