简体   繁体   中英

Commit count in Cake build script?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM