jfrog-cli icon indicating copy to clipboard operation
jfrog-cli copied to clipboard

Branch name is missing when collecting git info from GitLab

Open guybar opened this issue 1 year ago • 4 comments

When collecting git info from GitLab using the CLI command jf bag the GitLab branch name is not collected.

Expected: Collect the branch name from the GitLab CI_COMMIT_BRANCH environment variable, and save it as the branch name in the build info

guybar avatar Jan 12 '25 11:01 guybar

Hi @guybar , The jf rt bce command is used to collect environment variables to a build info.

The command you are looking for is jf rt bag which collects the Git revision and URL from the local .git directory and adds it to the build-info. See the docs for more info.

RobiNino avatar Feb 05 '25 13:02 RobiNino

you are correct, I was referring to the jf rt bag command, and you are correct it does not pick up the branch name, as you included in the example you had shared: "vcs": [ { "revision": "e2c0e017902db2715cf0d6e488e74d841860d969", "message": "Initial commit", "branch": "", "url": "[email protected]:username/test.git" } ]

guybar avatar Feb 06 '25 11:02 guybar

@guybar Arey you performing this on GitLab CI pipeline ?

If you are working on a GitLab CI pipeline and trying to collect environment variables from there, you will see them in the properties. However, this will not include Git details in the vcs section. For example:

{
    "properties": {
        "buildInfo.env.CI_COMMIT_BRANCH": "dev",

 }

Also if you are using build-add-git(jf rt bag) and haven't checkout to any branch on gitLab CI, it uses detached HEAD for the latest commit, which gives you vcs of

"vcs": [
        {
            "revision": "e2c0e017902db2715cf0d6e488e74d841860d969",
            "message": "Initial commit",
            "branch": "",
            "url": "[email protected]:username/test.git"
        }
    ]

This is what are you requesting for ?

agrasth avatar Feb 06 '25 11:02 agrasth

Hi @guybar,

Thank you for bringing this up!

As most CI pipelines run in a detached HEAD state, the branch name is not fetched by default. If we need to explicitly collect the branch name, we would first need to check out to the branch and then capture it. Each CI/CD platform provides its own environment variable to retrieve the current branch:

CI/CD Platform Environment Variable Notes
GitLab CI CI_COMMIT_BRANCH Directly provides the branch name
GitHub Actions GITHUB_REF Needs processing to extract the branch
Jenkins GIT_BRANCH Branch name from SCM
Bitbucket Pipelines BITBUCKET_BRANCH Direct branch name
Azure DevOps BUILD_SOURCEBRANCHNAME Direct branch name
CircleCI CIRCLE_BRANCH Direct branch name
Travis CI TRAVIS_BRANCH Direct branch name

Since this requires implementing support for multiple CI/CD systems, this is being categorized as a feature request. We will take it up separately based on availability and priority.

Thanks again for your input! Let me know if you have any additional thoughts.

agrasth avatar Feb 12 '25 06:02 agrasth

This issue has been marked as stale due to 6 months of inactivity. As part of our effort to address every issue properly, please feel free to remove the stale label or keep this issue active by leaving a comment. Otherwise, it will be closed in 7 days

github-actions[bot] avatar Sep 24 '25 09:09 github-actions[bot]

This issue was closed due to 7 days of inactivity after being marked as stale. Feel free to reopen it if it remains relevant.

github-actions[bot] avatar Oct 06 '25 00:10 github-actions[bot]