act: 'needs' is not defined

Error ERRO[0002] Unable to interpolate string 'echo ${{ needs.pre.output1 }}' - [ReferenceError: 'needs' is not defined] when try to following workflow:

jobs:
  pre:
    runs-on: ubuntu-latest
    steps:
      - run: echo '::set-env name=VAR1::value1'
    outputs:
      output1: ${{ env.VAR1 }}

  job1:
    runs-on: ubuntu-latest
    needs: [pre]
    steps:
      - run: echo ${{ needs.pre.outputs.output1 }}

This syntax is working in workflow ran by Github Actions, as we do use it in our project’s CI.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 76
  • Comments: 35 (7 by maintainers)

Most upvoted comments

+1

This feature would be really helpful

This is a huge blocker for us. The “needs” parameter enables proper, efficient parallel jobs to be run that have a common set of steps that need to be run for all of them.

We have a number of applications that build for multiple environments but share several common steps. Without being able to use the “needs” option, we have to resort to duplicating steps and waiting on things to run serially which is FAR less than ideal.

Community needs “needs” 😃

+1

When I run this example https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-8

name: Diff AccessDB
on: [pull_request]

jobs:
  job1:
    runs-on: ubuntu-latest
    # Map a step output to a job output
    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"
  job2:
    runs-on: ubuntu-latest
    needs: job1
    steps:
      - run: echo ${{needs.job1.outputs.output1}} ${{needs.job1.outputs.output2}}

Then I am getting this error in the latest @master version when I run act.

ERRO[0003] Unable to interpolate string ‘${{ steps.step2.outputs.test }}’ - [TypeError: Cannot access member ‘outputs’ of undefined]

Is this a known limitation?

@cplee hi, is there any update on this… ?

I am seeing the same. It seems to only work with the first step of each job.

@hcguersoy-oc Just wanted to let you know if you didn’t notice; the fix was merged yesterday! 😃 (see: #629 as per mergify update)

I have tried your test workflow from https://github.com/nektos/act/pull/629 > pkg/model/workflow_test.go and it works 😃

[test/test2] ⭐  Run test2_1
| some-a_value
| some-b-value
[test/test2]   ✅  Success - test2_1

Then I inserted a single step ‘doSomething’ before the step with the output assignments and it failed, i.e. all output variables are empty 😦

jobs:
  test1:
    runs-on: ubuntu-latest
    steps:
      - id: doSomething
        run: echo "do something..."
      - id: test1_1
        run: |
          echo "::set-output name=a_key::some-a_value"
          echo "::set-output name=b-key::some-b-value"
    outputs:
      some_a_key: ${{ steps.test1_1.outputs.a_key }}
      some-b-key: ${{ steps.test1_1.outputs.b-key }}
  test2:
    runs-on: ubuntu-latest
    needs:
      - test1
    steps:
      - name: test2_1
        run: |
          echo "${{ needs.test1.outputs.some_a_key }}"
          echo "${{ needs.test1.outputs.some-b-key }}"
[test/test2] ⭐  Run test2_1
workflow-test/workflow/0] user=
|
|
[test/test2]   ✅  Success - test2_1

Can this bug be fixed soon?

Hope the next release is soon with this. Have a hard time convincing my team to think ACT first because of that 😃 Thanks for the work on act tought, i love it

+1