You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将调用者Workflow中的默认工作目录传递至可复用Workflow

How to Pass a Working Directory from Caller to Reusable GitHub Workflow

To pass your specified working directory (myfolder/python/serviceA) from the caller workflow to the reusable workflow and make it the default for all run steps, follow these corrected implementations:

1. Caller Workflow Adjustments

You need to properly reference the default working directory using GitHub Actions expression syntax (${{ ... }}) and pass it as an input to the reusable job. Here's the fixed code:

defaults:
  run:
    working-directory: myfolder/python/serviceA

jobs:
  reusable-job:
    uses: <owner>/<repo>/.github/workflows/<reusable-workflow-file>.yml@master
    with:
      working-directory: ${{ defaults.run.working-directory }}

Key fixes here:

  • Replaced the incorrect double curly braces ({{ ... }}) with GitHub's valid expression syntax ${{ ... }}
  • Corrected the typo deafults to defaults

2. Reusable Workflow Setup

In the reusable workflow, define a required input for the working directory, then set it as the default working directory for all run steps:

on:
  workflow_call:
    inputs:
      working-directory:
        required: true
        type: string  # Explicitly define the input type for clarity

defaults:
  run:
    working-directory: ${{ inputs.working-directory }}  # Apply the input as default

jobs:
  my-reusable-job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      
      - name: Verify working directory
        run: pwd  # This will output the passed directory path (myfolder/python/serviceA)
      
      - name: Run a custom command
        run: echo "Working in the specified directory!"

Notes:

  • All run steps in the reusable workflow will automatically use the passed directory unless you explicitly override it with a working-directory field in individual steps.
  • The input is marked as required to ensure the caller always provides a value, preventing runtime errors.

内容的提问来源于stack exchange,提问作者reach jaango

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 15:37:37