pirelenito / git-revision-webpack-plugin

🏗 Webpack plugin that generates VERSION and COMMITHASH files during build
https://www.npmjs.com/package/git-revision-webpack-plugin
MIT License
358 stars 48 forks source link

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

Open folmert opened 5 years ago

folmert commented 5 years ago

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 commented 5 years ago

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

luckyyyyy commented 5 years ago

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

ttha1 commented 4 years ago

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)

jameswilson commented 3 years ago

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 commented 3 years ago
  • 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