Using annotations to persist tag

What’s the best way to have a workflow persist/display the tag needed to grab a specific Docker image from Spinnaker? I think annotations would be the simplest just because it’s a string, but this seems tricky. What’s the best practice for this?

@sschipke,

According to your comments, you have a step in a job to get the tag of a specific Docker image from Spinnaker, then you want to use this tag in all other jobs in the same workflow. Right?

If so, you can use outputs to do this, instead of annotations.
The following is a simple demo as reference:

jobs:
  job1:
    . . .
    outputs:
      tag: ${{ steps.get_image_tag.outputs.image_tag }}
    steps:
      - name: Get Docker image tag
        id: get_image_tag
        run: |
          image_tag=$( <some commands to get image tag from Spinnaker> )
          echo "::set-output name=image_tag::$image_tag"

      - name: print tag
        run: echo "The tag is ${{ steps.get_image_tag.outputs.image_tag }}"
      . . .
      ----- other steps in this job -----

  job2:
    needs: job1
    . . .
    steps:
      - name: print tag
        run: echo "The tag is ${{ needs.job1.outputs.tag }}"
      . . .
      ----- other steps in this job -----

  ----- similar to other jobs, reference to job2 -----

Explanation:

  1. In job1, setup the step (name: Get Docker image tag, id: get_image_tag) to get the image tag from Spinnaker, and set an output (set-output command) to store the tag.
    If you are using an action on this step to get the image instead of directly executing some commands, you should make sure the action has an output parameter to store the tag. In this way, the command to set the output need to set as part of the operations in the action.

  2. Set an job level output “tag” for job1, and pass the value of the step level output “image_tag” to “tag”.

tag: ${{ steps.get_image_tag.outputs.image_tag }}
  1. In the subsequent jobs, set the each job needs job1. Then use the expression “needs.job1.outputs.tag” to access the tag in each job.
      - name: print tag
        run: echo "The tag is ${{ needs.job1.outputs.tag }}"

Related docs: