Skip to content

fix: resolve empty src_branch and src_tag in Konflux builds#321

Merged
Hyperkid123 merged 1 commit intoRedHatInsights:masterfrom
platex-rehor-bot:bot/RHCLOUD-43021
Apr 20, 2026
Merged

fix: resolve empty src_branch and src_tag in Konflux builds#321
Hyperkid123 merged 1 commit intoRedHatInsights:masterfrom
platex-rehor-bot:bot/RHCLOUD-43021

Conversation

@platex-rehor-bot
Copy link
Copy Markdown
Contributor

@platex-rehor-bot platex-rehor-bot commented Apr 16, 2026

Summary

  • Root cause: get_git_branch() used git branch --show-current which returns an empty string (not an error) in detached HEAD state — the default checkout mode in Konflux/Tekton CI pipelines. The if ! guard only caught non-zero exit codes, so empty output was silently returned as the branch name.
  • Fix: Refactored all three git helper functions (get_git_branch, get_git_tag, get_git_hash) to capture output into variables and check for empty values, with multiple fallback strategies for CI environments.
  • Dockerfile: Added SOURCE_GIT_BRANCH and SOURCE_GIT_TAG build args so Tekton pipelines can optionally pass branch/tag metadata when git-based detection is not possible.

Branch detection cascade

  1. git branch --show-current (regular checkout)
  2. git rev-parse --abbrev-ref HEAD (non-detached ref)
  3. git branch -r --points-at HEAD (remote branch at same commit)
  4. CI environment variables (SOURCE_GIT_BRANCH, GITHUB_HEAD_REF, GITHUB_REF_NAME, GIT_BRANCH, BRANCH_NAME)
  5. Fallback to "unknown"

Tag detection cascade

  1. git describe --tags --abbrev=0 (nearest tag in history)
  2. git tag --points-at HEAD (tag directly on current commit)
  3. SOURCE_GIT_TAG environment variable
  4. Fallback to "unknown"

Fixes RHCLOUD-43021

Test plan

  • Verify app.info.json has correct src_branch and src_tag in a Konflux build
  • Verify local Docker builds still produce correct metadata
  • Verify no regressions in existing test_app_info_json_content test

🤖 Generated with Claude Code

RHCLOUD-43021

The git metadata functions in build_app_info.sh relied on commands
that silently return empty strings in detached HEAD state (the
default checkout mode in Konflux/Tekton CI). Refactor all three
git helper functions to capture output and check for empty values,
with a cascade of fallback strategies:

- get_git_branch: try show-current, then symbolic-ref, then remote
  branch lookup via --points-at HEAD, then CI environment variables
- get_git_tag: try describe --tags, then tag --points-at HEAD, then
  SOURCE_GIT_TAG env var
- get_git_hash: capture and validate output before returning

Also adds SOURCE_GIT_BRANCH and SOURCE_GIT_TAG as Dockerfile build
args so Tekton pipelines can pass branch/tag metadata explicitly
when git-based detection is not possible.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Warning

Rate limit exceeded

@platex-rehor-bot has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 51 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 26 minutes and 51 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ab1dfcc-4114-4985-b100-8ef0fb466965

📥 Commits

Reviewing files that changed from the base of the PR and between 46fccd9 and e1aa068.

📒 Files selected for processing (2)
  • Dockerfile
  • build_app_info.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Hyperkid123 Hyperkid123 requested a review from a team April 17, 2026 10:42
@Hyperkid123 Hyperkid123 merged commit 3524787 into RedHatInsights:master Apr 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants