question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

{{branch}} is not set on pull request events

See original GitHub issue

Troubleshooting

Before submitting a bug report please read the Troubleshooting doc.

Behaviour

Using {{branch}} as outlined in https://github.com/docker/metadata-action#global-expressions does not work when pushing commits to a branch with a PR open.

Steps to reproduce this issue

  1. Open a PR for new branch
  2. Push commits
  3. Observe output of workflow

Expected behaviour

Docker tags should be outputted as follows assuming a branch foo and sha 12345

my/repo:12345-amd64
my/repo:foo-amd64
my/repo:foo-12345-amd64

Actual behaviour

{{branch}} is empty so the tags are as follows:

my/repo:12345-amd64
my/repo:-amd64
my/repo:-12345-amd64

Configuration

name: docker-metadata-test
on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["*"]
jobs:
  name: docker-metadata-test
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v3
    - name: Docker meta
       id: meta
       uses: docker/metadata-action@v3
       with:
         images: my/repo
         tags: |
           type=raw,value={{sha}}-amd64
           type=raw,value={{branch}}-amd64
           type=raw,value={{branch}}-{{sha}}-amd64

Logs

metadata step of logs with some parts redacted
2022-04-20T00:00:44.3789494Z ##[group]Run docker/metadata-action@v3
2022-04-20T00:00:44.3789795Z with:
2022-04-20T00:00:44.3790108Z   images: my/repo
2022-04-20T00:00:44.3790585Z   tags: type=raw,value={{sha}}-amd64
type=raw,value={{branch}}-amd64
type=raw,value={{branch}}-{{sha}}-amd64

2022-04-20T00:00:44.3791171Z   github-token: ***
2022-04-20T00:00:44.3791392Z ##[endgroup]
2022-04-20T00:00:44.8175981Z ##[group]Context info
2022-04-20T00:00:44.8232603Z eventName: pull_request
2022-04-20T00:00:44.8232917Z sha: 137b7b03cf19010d9f14a6315a7d8d7741b99b4a
2022-04-20T00:00:44.8233160Z ref: refs/pull/80/merge
2022-04-20T00:00:44.8233385Z workflow: docker-metadata-test
2022-04-20T00:00:44.8233598Z action: meta
2022-04-20T00:00:44.8233787Z actor: evandam
2022-04-20T00:00:44.8233989Z runNumber: 124
2022-04-20T00:00:44.8234191Z runId: 2192825535
2022-04-20T00:00:44.8234662Z ##[endgroup]
2022-04-20T00:00:44.8235061Z ##[group]Processing tags input
2022-04-20T00:00:44.8235683Z type=raw,value={{sha}}-amd64,enable=true,priority=200
2022-04-20T00:00:44.8236093Z type=raw,value={{branch}}-amd64,enable=true,priority=200
2022-04-20T00:00:44.8236831Z type=raw,value={{branch}}-{{sha}}-amd64,enable=true,priority=200
2022-04-20T00:00:44.8237290Z ##[endgroup]
2022-04-20T00:00:44.8237665Z ##[group]Processing flavor input
2022-04-20T00:00:44.8237895Z latest=auto
2022-04-20T00:00:44.8238091Z prefix=
2022-04-20T00:00:44.8238279Z prefixLatest=false
2022-04-20T00:00:44.8238484Z suffix=
2022-04-20T00:00:44.8238678Z suffixLatest=false
2022-04-20T00:00:44.8239104Z ##[endgroup]
2022-04-20T00:00:44.8326167Z ##[group]Docker image version
2022-04-20T00:00:44.8326749Z 137b7b0-amd64
2022-04-20T00:00:44.8327230Z ##[endgroup]
2022-04-20T00:00:44.8348648Z ##[group]Docker tags
2022-04-20T00:00:44.8349280Z my/repo:137b7b0-amd64
2022-04-20T00:00:44.8349838Z my/repo:-amd64
2022-04-20T00:00:44.8350355Z my/repo:-137b7b0-amd64
2022-04-20T00:00:44.8351069Z ##[endgroup]
2022-04-20T00:00:44.8353443Z ##[group]Docker labels
2022-04-20T00:00:44.8353828Z org.opencontainers.image.title=my_repo
2022-04-20T00:00:44.8354284Z org.opencontainers.image.description=description
2022-04-20T00:00:44.8354824Z org.opencontainers.image.url=https://github.com/my/repo
2022-04-20T00:00:44.8355332Z org.opencontainers.image.source=https://github.com/my/repo
2022-04-20T00:00:44.8355840Z org.opencontainers.image.version=137b7b0-amd64
2022-04-20T00:00:44.8356377Z org.opencontainers.image.created=2022-04-20T00:00:44.822Z
2022-04-20T00:00:44.8356850Z org.opencontainers.image.revision=137b7b03cf19010d9f14a6315a7d8d7741b99b4a
2022-04-20T00:00:44.8357230Z org.opencontainers.image.licenses=
2022-04-20T00:00:44.8357770Z ##[endgroup]
2022-04-20T00:00:44.8358909Z ##[group]JSON output
2022-04-20T00:00:44.8359141Z {
2022-04-20T00:00:44.8359395Z   "tags": [
2022-04-20T00:00:44.8359898Z     "my/repo:137b7b0-amd64",
2022-04-20T00:00:44.8360652Z     "my/repo:-amd64",
2022-04-20T00:00:44.8361195Z     "my/repo:-137b7b0-amd64"
2022-04-20T00:00:44.8361544Z   ],
2022-04-20T00:00:44.8361757Z   "labels": {
2022-04-20T00:00:44.8363964Z     "org.opencontainers.image.title": "my_repo",
2022-04-20T00:00:44.8364504Z     "org.opencontainers.image.description": "description",
2022-04-20T00:00:44.8364981Z     "org.opencontainers.image.url": "https://github.com/my/repo",
2022-04-20T00:00:44.8365506Z     "org.opencontainers.image.source": "https://github.com/my/repo",
2022-04-20T00:00:44.8366099Z     "org.opencontainers.image.version": "137b7b0-amd64",
2022-04-20T00:00:44.8366684Z     "org.opencontainers.image.created": "2022-04-20T00:00:44.822Z",
2022-04-20T00:00:44.8367285Z     "org.opencontainers.image.revision": "137b7b03cf19010d9f14a6315a7d8d7741b99b4a",
2022-04-20T00:00:44.8367724Z     "org.opencontainers.image.licenses": ""
2022-04-20T00:00:44.8368040Z   }
2022-04-20T00:00:44.8368250Z }
2022-04-20T00:00:44.8368809Z ##[endgroup]
2022-04-20T00:00:44.8370169Z ##[group]Bake definition file
2022-04-20T00:00:44.8370447Z {
2022-04-20T00:00:44.8371202Z   "target": {
2022-04-20T00:00:44.8371777Z     "docker-metadata-action": {
2022-04-20T00:00:44.8372031Z       "tags": [
2022-04-20T00:00:44.8372504Z         "my/repo:137b7b0-amd64",
2022-04-20T00:00:44.8373187Z         "my/repo:-amd64",
2022-04-20T00:00:44.8373693Z         "my/repo:-137b7b0-amd64"
2022-04-20T00:00:44.8374050Z       ],
2022-04-20T00:00:44.8374327Z       "labels": {
2022-04-20T00:00:44.8374689Z         "org.opencontainers.image.title": "my_repo",
2022-04-20T00:00:44.8375124Z         "org.opencontainers.image.description": "description",
2022-04-20T00:00:44.8375657Z         "org.opencontainers.image.url": "https://github.com/my/repo",
2022-04-20T00:00:44.8376194Z         "org.opencontainers.image.source": "https://github.com/my/repo",
2022-04-20T00:00:44.8376702Z         "org.opencontainers.image.version": "137b7b0-amd64",
2022-04-20T00:00:44.8377253Z         "org.opencontainers.image.created": "2022-04-20T00:00:44.822Z",
2022-04-20T00:00:44.8377729Z         "org.opencontainers.image.revision": "137b7b03cf19010d9f14a6315a7d8d7741b99b4a",
2022-04-20T00:00:44.8378187Z         "org.opencontainers.image.licenses": ""
2022-04-20T00:00:44.8378466Z       },
2022-04-20T00:00:44.8378768Z       "args": {
2022-04-20T00:00:44.8379288Z         "DOCKER_META_IMAGES": "my/repo",
2022-04-20T00:00:44.8379716Z         "DOCKER_META_VERSION": "137b7b0-amd64"
2022-04-20T00:00:44.8380053Z       }
2022-04-20T00:00:44.8380309Z     }
2022-04-20T00:00:44.8380513Z   }
2022-04-20T00:00:44.8380792Z }
2022-04-20T00:00:44.8381452Z ##[endgroup]

Download the log file of your build and attach it to this issue.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
felipecrscommented, Apr 25, 2022

@evandam I know this isn’t a solution for your problem, but if I were you, I would probably prefer to tag PRs with the pr number instead of the branch name. Like myimage:pr-123.

I find this more descriptive than the branch name itself, as often we just give it any names. Oftenly we even reuse the same branch name as they get deleted after PR merge anyway.

0reactions
crazy-maxcommented, May 5, 2022

Closing this one as pr number is a more reliable pattern.

Read more comments on GitHub >

github_iconTop Results From Across the Web

{{branch}} is not set on pull request events · Issue #191 · docker ...
Here {{branch}} returns the branch name that triggered the workflow run so it will be empty for a pull_request event as it's not...
Read more >
Pull Request is not detecting action when run via workflow_run
I have set branch rules so that any pull request on "master" must have these 2 workflows pass. When I make/update a PR...
Read more >
Running GitHub Actions only on certain pull requests
If you want to limit GitHub Actions jobs to run only if a pull request targets a particular branch, there's a built-in mechanism...
Read more >
My GitHub Actions workflows are not starting - Robs blog
The cause of this is that scheduled runs only trigger from the default branch (main). Several triggers behave this way, like a Pull...
Read more >
Pull request not building - Codefresh
Cause The trigger is not set up for pull requests. ... requests from forks; If using branch filters, be aware that for PR...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found