Gitversion: When using Jenkins Pipeline - version is calculated on pipeline repo

Created on 27 May 2019  路  4Comments  路  Source: GitTools/GitVersion

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 :

  1. do git checkout of my actual code repo to a separate sub-directory
  2. cd do it and run dotnet gitversion

Expected:
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:

  1. get the pipeline repo to a sub dir as well - did'nt work.
  2. paste the pipeline code directly in the UI - did the trick and I got my code version correct.

This is a major lost of jenkins functionality (handle jobs as code) - any solution will help :)

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings