tvdstaaij / node-git-describe

Git describe information at runtime, with semver support
36 stars 5 forks source link

Getting an 'empty' output with Vue.js as part of Jenkins build #34

Open jaw111 opened 10 months ago

jaw111 commented 10 months ago

I'm following the approach mentioned on https://stackoverflow.com/a/59951577/21503085

When I run my application locally, it works OK. However, when the build is run with vue-cli-service build in our Jenkins CI/CD process then the commit hash is not picked up.

To help debug, I logged the output from gitDescribeSync() call:

{"dirty":false,"raw":"","hash":"","distance":null,"tag":null,"semver":null,"suffix":"","semverString":null}

I tried variations like gitDescribeSync(__dirname) and gitDescribeSync(__dirname, { match: '[0-9]*' }) without success.

I assume this is not a bug in this project, more something to do with how vue-cli-service works, but hoping someone can give some help/guidance how to make it work.

TimothyJones commented 10 months ago

Are you doing a full checkout on your CI? Most CI does a shallow checkout of a single commit by default

jaw111 commented 10 months ago

I guess that is it. I see the git fetch has the --no-tags option.

jaw111 commented 10 months ago

Seems to be a bit more subtle than I thought.

We're running Jenkins in AWS EKS and there is some issue JENKINS-30600 whereby the git checkout is run in the remoting container, not the build container.

When we try to run git describe inside the build container, we then see the following:

+ git describe --match [0-9]*
fatal: detected dubious ownership in repository at '/home/jenkins/agent/workspace/_my-project_develop'
To add an exception for this directory, call:

    git config --global --add safe.directory /home/jenkins/agent/workspace/_my-project_develop

Which seems to be a feature where Git now checks for ownership of the folder.

If I add the exception, then everything works OK, but I'm puzzled why gitDescribeSync() doesn't crash and burn if the underlying command is throwing a fatal error.