-
Notifications
You must be signed in to change notification settings - Fork 300
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
git.branch in maven under jenkins pipelines is wrong evaluated to the commit #325
Comments
Hi, thanks for reporting your problem here! Can you provide me some more details about the following so I could potentially reproduce the issue:
Anything on the setup side would potentially help to trace this down and get it fixed |
|
After a first quick investigation what might be the problem...it seems that this is caused by using pipelines... The root cause why the commit-id is being displayed for branch is related how jenkins/hudson are cloning and using git. Usally jenkins performs a shallow clone of the repo and then checking out a specific commit (HEAD). With normal git-features AFAIK from that point we don't know on which branch we are without performing ugly git-magic (TODO investigate me). Usually the trick to get this plugin working on Jenkins/Hudson is using the exposed environment variables. When this plugin doesn't find any environment variables for the branch it will defaults to the commit-id. The general question that seems to be the problem here: My pipeline-script being used for testing:
|
Just as an update to summarize:
I'll do some more investigation with the Multibranch-Pipeline if the branch is being determined correctly.... |
Alright; I'll stop investigating this further..... Tested the following without any success (besides defining the extra parameter):
I won't test this for a multi-branch projects since I'll open a ticket with jenkis. The plugin is behaving correctly, but jenkins fails to give the plugin the required information :-( Just as a side node, I noticed that whatever is being defined as param is also getting exposed as environment-variable and thus there is no need to specify an additional environment block inside the groovy script; simply use GIT_BRANCH instead of branch aka.:
Just note, that this does not work for the first build, unless you specify manually that the build is parametrized and use the same parameters as in the groovy script - feel free to open issues with jenkins on this one. PS: |
I have used now following workaround in my pom.xml for maven
From jenkins pipeline I call now following step
In my development environment I call mvn without -DBranch, as there maven-git-commit-id-plugin works fine. |
Thanks for the feedback and glad you found another workaround! |
This is still an issue. It can be fixed with workaround in #325 (comment) |
It's possible to overwrite branch in a more simple way: |
got the same issue ... |
I also have the same issue. Is there a solution? |
If you get solution for this issue. Kindly share it here. |
Workarounds are available: Ask jenkins to implement this correctly. |
@TheSnoozer Sure, Thanks for your response. One quick question, which environment variable will be used to capture the value of git.branch in git.properties during the Maven build process on Jenkins? |
First this plugin ties GIT_LOCAL_BRANCH after that GIT_BRANCH. |
@TheSnoozer , Thanks for the quick response. I would like to know if there is any difference between git-commit-id-maven-plugin and git-commit-id-plugin-core. I noticed that both repositories are part of the git-commit-id project. |
git-commit-id-plugin-core == Shared library code for all git-commit-id-*plugin(s) So if you search any logic implementation it is likely encoded in git-commit-id-plugin-core, while when you search maven related logic it is solely encoded in the git-commit-id-maven-plugin. |
I have maven pom.xml, where I use git.branch and git.commit.id.abbrev to create database schema for my tests.
This works fine, when I call maven in my development environment.
But when maven is called from a jenkins pipeline on the same branch, then git.branch is replaced with the full commit id.
This seems to be related to the detached mode of jenkins pipeline working copies of the workspace:
The text was updated successfully, but these errors were encountered: