Home > Mobile >  Github Action needs context is not available in container.image
Github Action needs context is not available in container.image

Time:08-10

I'm trying to parametrize the jobs.myjob.container.image field. The documentation says the needs context is available there:

Contexts documentation

Specifically this:

Workflow key Context
jobs.<job_id>.container github, needs, strategy, matrix, env, secrets, inputs

But it doesn't work. My job output is an empty string, causing an error.

  get_image:
    name: get_image
    runs-on: self-hosted
    outputs:
      image: ${{ steps.jq.image }}
    needs:
      - ...
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: jq
        id: jq
        run: |
          set -x
          export TAG=$(jq -r '.${{ github.event.inputs.cluster }} | .tag' data.json)
          echo "::set-output name=image::registry.com/mycontainer:$TAG"

  job2:
    name: job2
    runs-on: self-hosted
    needs:
      - get_image
    container:
      image: ${{ needs.get_image.outputs.image }} <--- this is an empty string
      credentials:
        ...
    steps:
        ...

The error I'm getting is Error: The template is not valid. ...: Unexpected value ''.

Is the documentation lying to me or am I just reading it wrong?

Other questions lead me to think that the thing I want to do is not allowed.

CodePudding user response:

You should use outputs here image: ${{ steps.jq.outputs.image }}.

  • Related