Repository navigation
Adding a label containing an octothorpe (#) incorrectly results in the label being stripped #451
Description
Activity
Yes this relates to #172 to enable comments for these inputs:
metadata-action/src/context.ts
Lines 24 to 28 in 60a0d34
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.
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 usescsv-parseto 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-parsewill 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-parseis 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
- marked tags input breaks when using # in Git tag or regex #546 as a duplicate of this issue
on Aug 20, 2025 @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
Added to v6 milestone
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
Contributing guidelines
I've found a bug, and:
Description
Specifying a label
mylabel=foo#barresults in the labelmylabel=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#barActual behaviour
The Docker labels output of the action includes
mylabel=fooRepository 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#barWorkflow 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.