Skip to content

CircleCI orb fails on tag builds: --branch parameter not exposed #598

@kaarla

Description

@kaarla

The find-code-references job fails on CircleCI tag builds with:

error parsing git tag name: git repo at /repo must be checked out to a valid branch or tag, or --branch option must be set

On tag builds, CircleCI checks out in detached HEAD state and sets CIRCLE_TAG but leaves CIRCLE_BRANCH empty. The binary's internal tag detection (via go-git) fails to identify the tag in this state, even though the tags are locally available and git describe --tags --exact-match HEAD works correctly.

The binary supports --branch to bypass git auto-detection entirely and passing it explicitly works:

  ld-find-code-refs --branch=$CIRCLE_TAG ...  # works
  LD_BRANCH=$CIRCLE_TAG ld-find-code-refs ... # also works

However, the CircleCI orb job does not expose --branch as a parameter, so there is no clean way to pass it.

Expected behavior

One of:

  1. The orb detects CIRCLE_TAG when CIRCLE_BRANCH is empty and passes --branch=$CIRCLE_TAG automatically
  2. The orb exposes a branch parameter that maps to --branch

Workaround

Intercept the binary in a pre-steps wrapper that injects LD_BRANCH:

  pre-steps:
    - run:
        name: Inject branch name for tag builds
        command: |
          if [ -n "$CIRCLE_TAG" ]; then
            BINARY=$(which ld-find-code-refs)
            mv "$BINARY" "${BINARY}.orig"
            printf '#!/bin/sh\nexport LD_BRANCH="$CIRCLE_TAG"\nexec "%s.orig" "$@"\n' \
              "$BINARY" > "$BINARY"
            chmod +x "$BINARY"
          fi

Note: $BASH_ENV does not work here because the orb's Docker image (launchdarkly/ld-find-code-refs) uses Alpine/sh, which does
not source $BASH_ENV automatically.

Steps to reproduce

  1. Add the launchdarkly/find-code-references job to a CircleCI workflow
    with allow_tags: true and tag filters:
    - launchdarkly/find-code-references:
        allow_tags: true                                                                                                 
        filters: 
          tags:
            only: /.+/
  2. Push an annotated tag:
    git tag -a 1.0.0 -m "release" && git push origin 1.0.0
  3. Observe the CircleCI job fails with:
    error parsing git tag name: git repo at /repo must be checked to a valid branch or tag, or --branch option must be set

Environment

  • Orb launchdarkly/ld-find-code-refs
  • CircleCI tag build (CIRCLE_TAG set, CIRCLE_BRANCH empty)
  • Annotated tags

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions