Skip to content

Adding a label containing an octothorpe (#) incorrectly results in the label being stripped #451

Description

@tomdoel

Contributing guidelines

I've found a bug, and:

  • The documentation does not mention anything about my problem
  • There are no open or closed issues that are related to my problem

Description

Specifying a label mylabel=foo#bar results in the label mylabel=foo. It appears that the octothorpe (#) is incorrectly interpreted as the start of a comment and the rest of the label is removed.

Expected behaviour

The Docker labels output of the action should include mylabel=foo#bar

Actual behaviour

The Docker labels output of the action includes mylabel=foo

Repository URL

No response

Workflow run URL

No response

YAML workflow

-
        name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
          labels: |
            mylabel=foo#bar

Workflow logs

No response

BuildKit logs

No response

Additional info

The behaviour was correct in v3.6.2 and seems to have broken around v3.7.0.

Activity

  1. crazy-max commented on Aug 22, 2024

    @crazy-max
    Member

    Yes this relates to #172 to enable comments for these inputs:

    images: Util.getInputList('images', {ignoreComma: true, comment: '#'}),
    tags: Util.getInputList('tags', {ignoreComma: true, comment: '#'}),
    flavor: Util.getInputList('flavor', {ignoreComma: true, comment: '#'}),
    labels: Util.getInputList('labels', {ignoreComma: true, comment: '#'}),
    annotations: Util.getInputList('annotations', {ignoreComma: true, comment: '#'}),

    Disabling comments would be a breaking change though so you can either escape this char or we could introduce an env var to disable comments.

  2. tomdoel commented on Aug 23, 2024

    @tomdoel
    Author

    Thanks for the update.

    So as I understand it, the underlying issue was that YAML does not allow comments in multi-line scalar inputs:

    -
    labels: |
      # This is not a valid YAML comment; it is part of the labels input
      mylabel=foo#bar

    So in order to allow for comments in the labels input, metadata-action calls getInputList, which uses csv-parse to remove the comments. But this also removes parts of the labels containing #.

    I don't think it's possible to escape #, but I can force quotes around the label. csv-parse will remove the quotes and accept the whole label instead of interpreting the comment. So for example, this works:

    - name: Docker meta
      id: meta
      uses: docker/metadata-action@v5
      with:
        images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
        labels: "
          \"mylabel=foo#bar\""

    However this feels a little fragile as it relies on the implementation detail that csv-parse is being used to process the inputs.

    So instead I am using the following workaround where I append the custom label to the push action instead of the meta action:

    - name: Docker meta
      id: meta
      uses: docker/metadata-action@v5
      with:
        images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
    
    - name: Build and push Docker image
      id: push
      uses: docker/build-push-action@v6
      with:
        context: .
        push: true
        tags: ${{ steps.meta.outputs.tags }}
        labels: |
          ${{ steps.meta.outputs.labels }}
          mylabel=foo#bar
  3. theanurin commented on Aug 20, 2025

    @theanurin

    @crazy-max
    I want to invest time into the issue...
    Do you have an idea for right solution?

    May be something like this:

    - name: Docker meta
      id: meta
      uses: docker/metadata-action@v5
      with:
        comment: "//"
        labels: |
          mylabel=foo#bar // this is a comment
  4. added this to the v6 milestone on Nov 4, 2025
  5. crazy-max commented on Nov 4, 2025

    @crazy-max
    Member

    Added to v6 milestone

  6. crazy-max commented on Mar 5, 2026

    @crazy-max
    Member

    Opened #607

    Can be tested with:

            - name: Docker meta
              id: meta
              uses: crazy-max/docker-metadata-action@allow-comments
              with:
                images: acme/myapp
                labels: |
                  # full line comment allowed
                  org.opencontainers.image.revision=${{ github.sha }}#source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions