Skip to content

Implement reusable workflows

Current situation

The orchestrator can run workflows, but it cannot run another workflow from a workflow as a set of jobs of this main workflow.

Desired outcome

With reference to the respective study (https://gitlab.com/henixdevelopment/squash/squash-autom-devops/squash-orchestrator/-/issues/253), implement the feature.

The following workflow should download the workflow file defined in the uses part of the job-1 to an execution environment, attach it to itself, and run it. Called workflow inputs and outputs should be available to the main workflow.

metadata:
  name: Main
jobs:
  job-1:
    runs-on: ['linux']
    uses: {repository}#{repository_name/path/workflow.yaml}@{branch}
    with:
      input_a: foo
      input_b: bar
outputs:
  job-1-output:
    value: ${{ jobs.job-1.outputs.workflow_output2 }}

uses syntax

The uses part (mandatory) defines git repository to clone (mandatory), called workflow path (mandatory), and branch to check out (optional).

The with part (optional) defines called workflow inputs. These inputs should match the inputs defined in the called workflow, otherwise the job fails.

Configuration parameters

The uses job creates a sub-job .download, that checks out the git repository and downloads the workflow file from the path specified. This job runs-on tags are configurable.

The download_job_tags configuration parameter should be added to the arranger plugin configuration. It is a string of comma-separated values that defines the environment used to download the called workflow.

The download_job_parents_tags configuration parameter should be added to the arranger plugin configuration. This parameter determines whether to use or ignore uses jobs tags in .download job and has two possible values, use and ignore.

For example, if the download_job_tags value is foo,bar, the download_job_parents_tags value is use and the uses job runs-on is ['linux'], the .download job will be executed on the environment determined by foo,bar,linux tags.

Inputs and outputs

When the main workflow calls the following workflow, it should be executed as a set of jobs of the main workflow. It should display "hello bar" as a result of the inputs-job, and the value "world" should be available as an output of the main workflow.

metadata:
  name: Inputs and outputs
inputs:
  input_a: 
    description: 'Input a'
    required: false
    default: '1'
  input_b: 
    description: 'Input b'
    required: false
    default: '1'
jobs:
  inputs-job:
    runs-on: ['linux']
    steps:
      - run: echo "hello ${{ inputs.input_b }}"
  output-job:
    runs-on: ['linux']
    outputs:
      output1: ${{ steps.step1.outputs.test }}
      output2: ${{ steps.step2.outputs.test }}
    steps:
    - id: step1
      run: echo "::set-output name=test::hello"
    - id: step2
      run: echo "::set-output name=test::world"
outputs:
  workflow_output1:
    description: "The first job output"
    value: ${{ jobs.output-job.outputs.output1 }}
  workflow_output2:
    description: "The second first job output"
    value: ${{ jobs.output-job.outputs.output2 }}
Edited by Maria Einman