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

Use git log instead git rev-parse to get current branch #41

Open
folmert opened this issue Jan 17, 2019 · 5 comments
Open

Use git log instead git rev-parse to get current branch #41

folmert opened this issue Jan 17, 2019 · 5 comments

Comments

@folmert
Copy link

folmert commented Jan 17, 2019

git rev-parse --abbrev-ref HEAD isn't very helpful, as it always returns HEAD when you're in detached HEAD state (i.e. when deploying via gitlab).

I suggest using git log -n 1 --pretty=%d HEAD instead, in detached HEAD state it produces a more meaningful output:
(HEAD, origin/sandbox/test_git_revision_plugin)

@jpogorzelski
Copy link

I agree, when deploying via travis it's useless - it always returns HEAD.

@luckyyyyy
Copy link

I agree, when deploying via gitlab it's useless - it always returns HEAD.

@ttha1
Copy link

ttha1 commented Feb 25, 2020

When building on CI servers, the value should come from specific environment variables (for more info see https://github.com/n0mer/gradle-git-properties/blob/master/src/main/groovy/com/gorylenko/properties/BranchProperty.groovy)

  • Jenkins/Hudson: GIT_LOCAL_BRANCH / GIT_BRANCH / BRANCH_NAME
  • TravisCI: TRAVIS_BRANCH
  • TeamCity: teamcity.build.branch
  • Gitlab: CI_COMMIT_REF_NAME
  • Bamboo: BAMBOO_PLANREPOSITORY_BRANCH

@jameswilson
Copy link

I use this configuration:

new GitRevisionPlugin({
  branch: true,
  versionCommand: "describe --tags --always --dirty | sed -En 's/-dirty/~/p'",
  branchCommand:
    "describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD",
});

Which gives nicely formatted version strings no matter if you're currently on a tag, a branch, or worst-case a detached head, in which case it falls back to the short git hash.

@yh36
Copy link

yh36 commented Oct 25, 2021

  • GIT_BRANCH

For Jenkins, the env var, "BRANCH_NAME", is only available for a multibranch project. And there are no "GIT_LOCAL_BRANCH" and "GIT_BRANCH" in Jenkins. I'm using Jenkins 2.303.2

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

No branches or pull requests

6 participants