Home > Enterprise >  Github Reusable Workflow jobs.<job_id>.needs with input parameter
Github Reusable Workflow jobs.<job_id>.needs with input parameter

Time:07-15

I use reusable workflows and then execute it throw the workflow

Template.yml:

name: Reusable workflow
on:
  workflow_call:
    inputs:
      jobName:
        required: true
        type: string
      jobDependencies:
        required: true
        type: string
jobs:
  deployNotebook:
    name: Deployment ${{ inputs.jobName }} env
    runs-on: ubuntu-latest
    needs: ${{ inputs.jobDependencies }}
    steps:
      - name: Deployment of Job
        run: echo Hello world

Workflow.yml:

name: Workflow which use Template    
on:
  workflow_dispatch:
jobs:
  validation:
    name: Workflow validation
    runs-on: ubuntu-latest
    steps:
      - name: Deployment of Notebook
        shell: pwsh
        run: Write-Host 'Workflow successfully parsed'
  dev:
    uses: ./.github/workflows/Template.yml
    with: 
      jobName: 'dev'
      jobDependencies: 'validation'
  test:
    uses: ./.github/workflows/Template.yml
    with: 
      jobName: 'test'
      jobDependencies: 'dev'

When I run this I receive error:

Unrecognized named-value: 'inputs'. Located at position 1 within expression: inputs.jobDependencies

At the same time ${{ inputs.jobName }} working fine. If I commented out ${{ inputs.jobDependencies }} everything working fine.

How can I use jobs.<job_id>.needs with an inputs provided from outside?

CodePudding user response:

Have found workaround with IF statement outside the template, meant in Workflow.yml

Same thing with Needs, which could be used just outside template

  • Related