Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch name is missing when collecting git info from GitLab #2827

Open
guybar opened this issue Jan 12, 2025 · 4 comments
Open

Branch name is missing when collecting git info from GitLab #2827

guybar opened this issue Jan 12, 2025 · 4 comments
Labels
feature request New feature or request

Comments

@guybar
Copy link

guybar commented Jan 12, 2025

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 guybar added the feature request New feature or request label Jan 12, 2025
@RobiNino
Copy link
Contributor

RobiNino commented Feb 5, 2025

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.

@guybar
Copy link
Author

guybar commented Feb 6, 2025

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" } ]

@agrasth
Copy link
Collaborator

agrasth commented Feb 6, 2025

@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
Copy link
Collaborator

agrasth commented Feb 12, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants