fix: resolve empty src_branch and src_tag in Konflux builds#321
Conversation
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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
get_git_branch()usedgit branch --show-currentwhich returns an empty string (not an error) in detached HEAD state — the default checkout mode in Konflux/Tekton CI pipelines. Theif !guard only caught non-zero exit codes, so empty output was silently returned as the branch name.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.SOURCE_GIT_BRANCHandSOURCE_GIT_TAGbuild args so Tekton pipelines can optionally pass branch/tag metadata when git-based detection is not possible.Branch detection cascade
git branch --show-current(regular checkout)git rev-parse --abbrev-ref HEAD(non-detached ref)git branch -r --points-at HEAD(remote branch at same commit)SOURCE_GIT_BRANCH,GITHUB_HEAD_REF,GITHUB_REF_NAME,GIT_BRANCH,BRANCH_NAME)"unknown"Tag detection cascade
git describe --tags --abbrev=0(nearest tag in history)git tag --points-at HEAD(tag directly on current commit)SOURCE_GIT_TAGenvironment variable"unknown"Fixes RHCLOUD-43021
Test plan
app.info.jsonhas correctsrc_branchandsrc_tagin a Konflux buildtest_app_info_json_contenttest🤖 Generated with Claude Code