Jobs outputs is not working

I have this job, and it builds the docker container and pushes correctly

jobs:
  build-postgres:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    outputs:
      tag: ${{ steps.tag.outputs.tag }}
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - uses: docker/setup-buildx-action@v1
      - uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-
      - uses: ./.github/actions/git-short-ref
        id: ref
      - uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
      - uses: aws-actions/amazon-ecr-login@v1
        id: login-ecr
      - run: echo -n ::set-output name=tag::"${{ steps.login-ecr.outputs.registry }}/cloud-stack/postgres:${{ steps.ref.outputs.ref }}"
        id: tag
      - uses: docker/build-push-action@v2
        id: build
        with:
          context: postgres
          file: postgres/Dockerfile
          load: true
          tags: ${{ steps.tag.outputs.tag }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache
      - run: docker push ${{ steps.tag.outputs.tag }}

but in this job where I go to rely on the needs output of the previous job it doesn’t work, it’s just empty.

  test-migrations:
    needs: [build-postgres, build-migrations]
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v2
      - uses: docker/setup-buildx-action@v1
      - uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-
      - uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
      - uses: aws-actions/amazon-ecr-login@v1
        id: login-ecr
      - run: docker network create skynet
      - run: |
          set -e
          export ID=$(docker run \
            --publish 5432:5432 \
            --network skynet \
            --network-alias db.host \
            --env-file .github/env/postgres \
            --detach ${{ needs.build-postgres.outputs.tag }} )
          echo -n "::set-output name=container-id::$ID"
        shell: bash
        id: pg-run

I don’t see a problem with my code, but there must be, what am I don’t wrong?

@xenoterracide,

Try this to see if it can work:

echo "::set-output name=tag::${{ steps.login-ecr.outputs.registry }}/cloud-stack/postgres:${{ steps.ref.outputs.ref }}"

In addition, make sure the jobs “build-postgres”, “build-migrations” and “test-migrations” are in the same workflow run.

jobs:
  experiement:
    runs-on: ubuntu-latest
    outputs:
      registry: ${{ steps.registry.outputs.registry }}
    steps:
      - run: echo "::set-output name=registry::myregistry"
        id: registry
  peer:
    needs: [experiement]
    timeout-minutes: 5
    runs-on: ubuntu-latest
    steps:
      - run: echo ${{ needs.experiement.outputs.registry }}

yes I know about the spelling error

seems like this is working but if I do exactly the same thing with actual registry output, I don’t get any output.

  experiement:
    runs-on: ubuntu-latest
    outputs:
      registry: ${{ steps.login-ecr.outputs.registry }}
    steps:
      - uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
      - uses: aws-actions/amazon-ecr-login@v1
        id: login-ecr

@xenoterracide,

Can the value of the output be get normally at the subsequent steps in the same job where the output is set?
In your case, if you set a step in “experiement” job to read the value of the output, does it can work normally?

jobs:
  experiement:
    runs-on: ubuntu-latest
    outputs:
      registry: ${{ steps.registry.outputs.registry }}
    steps:
      - run: echo "::set-output name=registry::myregistry"
        id: registry

      - name: view output
        run: echo "steps.registry.outputs.registry = ${{ steps.registry.outputs.registry }}"

I have the exact same issue, the answer is yes, it is possible to see the output in the same job

I am facing the same issue. The output is available in the next step but not in the next job. The output of

- env:
    NEEDS: ${{ toJson(needs) }}
  run: echo "$NEEDS"

is

{
  "job-name": {
    "result": "success",
    "outputs": {}
  }
}

As you can see, the outputs object comes out empty.

For me, the issue was that the secrets were being blocked from being used in output variables. I noticed this from the warning message on the workflow summary after a run that reported successful:
image

The fix:

  1. One of my steps uses aws-actions/configure-aws-credentials@v1.
    This action will mask your account-id by default, which was causing my issue. The Fix here is to pass parameter mask-aws-account-id: 'no' (Source)
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-east-2
        mask-aws-account-id: 'no'
  1. I was also using a secret for the aws-region, which caused the my output var to be blocked as well. Basically, your output variable will be blocked if it contains any secrets. So to fix this, I hardcoded the aws-region to us-east-2.

We are experiencing this issue as well. It is very hard to debug this issue and we can’t solve it.
We declare an output and can access it in the same job but it’s gone in the next job:

This is our workflow:

name: Repo Scanner
on: push

jobs:
  filter:
    name: Filter Repos
    runs-on: ubuntu-20.04
    outputs:
      repos: ${{ steps.output_repos.repos_list }}

    steps:
      - id: query_repos
        name: Query All Repos
        run: echo '["gruffalo-mirror", "hello"]' > repos.json
      - id: echo_repos
        name: Echo All Repos
        run: cat repos.json
      - id: output_repos
        name: Output
        run: echo "::set-output name=repos_list::hello"
      - id: print_steps
        env:
          STEPS: ${{ toJson(steps) }}
        run: echo "$STEPS"
      - id: print_job
        env:
          JOB: ${{ toJson(job) }}
        run: echo "$JOB"

  scan:
    name: Scan Repo
    runs-on: ubuntu-20.04
    needs: filter

    steps:
      - id: print_needs
        env:
          NEEDS: ${{ toJson(needs) }}
        run: echo "$NEEDS"
      - id: scan_repo
        name: Scan
        run: echo ${{ needs.filter.outputs.repos }}

We get the following output in the first job:

Run echo "$STEPS"
{
  "output_repos": {
    "outputs": {
      "repos_list": "hello"
    },
    "outcome": "success",
    "conclusion": "success"
  }
}

Run echo "$JOB"
{
  "status": "success"
}

But in the second one there is no output defined:

Run echo "$NEEDS"
{
  "filter": {
    "result": "success",
    "outputs": {}
  }
}

@brightran is there anything we can do to solve this? This seems like a bug.

Experiencing this as well myself. It appears that if an output is masked, then that output is blank for any subsequent jobs, but not subsequent steps within the same job. This is slightly inconvenient for some of the workflows I am attempting to set up.

Looks like you are not setting the output correctly:

     outputs:
-      repos: ${{ steps.output_repos.repos_list }}
+      repos: ${{ steps.output_repos.outputs.repos_list }}

There is a missing outputs here after the step ID, compared to the documentation. Try this:

    outputs:
      repos: ${{ steps.output_repos.outputs.repos_list }}