We’re migrating to using Cake build scripts for our CI pipeline and in our build process we identify builds with the commit count using the output from command git rev-list --all –count.
Is there a native way for this in Cake without shelling out to the git command line?
While there’s no built-in alias for this, there’s an addin to Cake called Cake.Git which enables you to achieve what you’re asking for.
Example usage:
#addin nuget:?package=Cake.Git
DirectoryPath repoPath = Directory("path to repo");
var commits = GitLog(repoPath, int.MaxValue);
Information("Number of commits: {0}", commits.Count);
Will out put something like
Number of commits: 1539
Just wanted to point out an alternative as well...
I, and Cake itself, use a tool called GitVersion to assert a semantic version number, based on the git commit history. Just wanted to point it out, in case it might be a good fit for your pipeline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With