Open folmert opened 5 years ago
I agree, when deploying via travis it's useless - it always returns HEAD.
I agree, when deploying via gitlab it's useless - it always returns HEAD.
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)
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.
- 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
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)