it:ad:mercurial:howto:get_the_revision_number

IT:AD:Mercurial:HowTo:Get Hg Revision Number

The idea is to use the hg command to get back the info you want:


C:\Program Files (x86)\Jenkins\jobs\XAct.Core\workspace>hg id -n
506

C:\Program Files (x86)\Jenkins\jobs\XAct.Core\workspace>hg id -i
3299e65cecfb

C:\Program Files (x86)\Jenkins\jobs\XAct.Core\workspace>hg id
3299e65cecfb tip

C:\Program Files (x86)\Jenkins\jobs\XAct.Core\workspace>hg heads
changeset:   506:3299e65cecfb
tag:         tip
user:        skysigal
date:        Thu Mar 14 20:27:20 2013 +1300
summary:     Moved Folders



Then wrap that up in a C# method that can be scripted up

private void GetMercurialVersion()
        {
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WorkingDirectory = DirectoryPath;
            p.StartInfo.FileName = "hg";
            p.StartInfo.Arguments = "id";
            p.Start();

            string output = p.StandardOutput.ReadToEnd().Trim();
            Log.LogMessage(MessageImportance.Normal, "Standard Output: " + output);

            string error = p.StandardError.ReadToEnd().Trim();
            Log.LogMessage(MessageImportance.Normal, "Standard Error: " + error);

            p.WaitForExit();

            Log.LogMessage(MessageImportance.Normal, "Retrieving Mercurial Version Number");
            Log.LogMessage(MessageImportance.Normal, output);

            Log.LogMessage(MessageImportance.Normal, "DirectoryPath is {0}", DirectoryPath);
            MercurialId = output;

        }

  • /home/skysigal/public_html/data/pages/it/ad/mercurial/howto/get_the_revision_number.txt
  • Last modified: 2023/11/04 01:49
  • by 127.0.0.1