Home > Software design >  Keyword secrets is not working in github actions workflow
Keyword secrets is not working in github actions workflow

Time:07-29

Workflow that call reusable one:

name: Build only workflow

on:
  pull_request:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/workflows/build_job
        with:
          TARGET: lol
        secrets: inherit

./.github/workflows/build_job folder contain action.yml file:

name: Build job

on:
  workflow_call:
    inputs:
      TARGET:
        required: true
        type: string

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: webfactory/[email protected]
        with:
            ssh-private-key: ${{secrets.SSH_KEY}}
      - run: echo "hello"

Error: The workflow is not valid. .github/workflows/build_workflow.yml (Line: 16, Col: 9): Unexpected value 'secrets'

enter image description here

CodePudding user response:

You're including the reusable workflow as a step, but a reusable workflow is an entire job not just a step.

Therefore, what you need is:

jobs:
  my-job:
    uses: ./.github/workflows/my-reusable-workflow.yaml

And then, since you can't do the checkout from outside anymore, you're going to have to add the checkout to your reusable workflow.

Also see this other answer of mine on the distinction between composite actions and reusable workflows.

  • Related