I'm using Pipeline as code on Jenkins- every build triggers a checkout from my pipelines repo to retrieve the job pipeline script.
the pipeline flow is :
dotnet gitversionExpected:
get a calculated version of my actual code repo
Actual:
I get the version of my pipeline repo
steps I did to try to workaround:
This is a major lost of jenkins functionality (handle jobs as code) - any solution will help :)
GitVersion only cares about the closest .git folder it can find. If that contains the repository data for the Jenkins pipeline, then that's what GitVersion is going to calculate a version for. With #1691 it will be possible to provide a path to where GitVersion.yml and thus also where the repository (the .git folder) resides. Is that going to help you in any way?
When GitVersion detects Jenkins by existence of JENKINS_URL env variable it ignores the information from .git folder, and instead uses the values from GIT_BRANCH and GIT_LOCAL_BRANCH env variables.
In our case, the Jenkins pipeline was triggered by another pipeline, and not directly by a git repo related event, and thus, didn't have the correct env variables set.
We fixed our problem by setting GIT_BRANCH and GIT_LOCAL_BRANCH to the right values before calling GitVersion.
Maintainers can close this issue.
@danielkatz thanks for sharing your solution. Closing this one
Can anyone provide an example of a jenkins declarative pipeline properly done? The documentation tells you how to do it in the UI but not in code.
Most helpful comment
Can anyone provide an example of a jenkins declarative pipeline properly done? The documentation tells you how to do it in the UI but not in code.