5

मेरे पास क्रूज़ कंट्रोल.NET में स्थापित दो परियोजनाएं हैं: सीआई बिल्ड और रात का निर्माण।मैं एकाधिक CruiseControl.NET बिल्ड के बीच लेबल मान कैसे साझा करूं?

उनमें से दोनों एक ही NANT स्क्रिप्ट निष्पादित करते हैं, लेकिन विभिन्न मानकों के साथ।

CruiseControl.NET लेबल (वर्तमान में DefaultLabeler द्वारा उत्पन्न) संस्करण के निर्माण भाग (उदाहरण के लिए, MajorVersion.MinorVersion.CCNET_Label.SVN_Revision) के रूप में AssemblyInfo में एम्बेडेड है।

अधिक संगत संस्करण के लिए मैं दोनों परियोजनाओं को एक ही क्रूज़ कंट्रोल.NET लेबल मान साझा करना चाहता हूं।

मैंने उन लेबलर्स की जांच की है जो CruiseControl.NET स्थापना के हिस्से के रूप में उपलब्ध हैं, लेकिन मुझे वह नहीं मिला जो मैं चाहता हूं।

मैं एकाधिक CruiseControl.NET बिल्डों के बीच लेबल मान कैसे साझा करूं?
यदि ऐसा करने का एक बेहतर तरीका है, तो मैं जानना चाहता हूं।

मुझे एक रास्ता मिला। नीचे मेरा जवाब देखें।

उत्तर

9

मुझे एक मौजूदा समाधान नहीं मिला जो मुझे चाहिए, इसलिए मैंने एक कस्टम क्रूज़ कंट्रोल.NET प्रयोगशाला लिखना समाप्त कर दिया।

यहाँ यह कैसे किया जाता है है:

  1. कोई नया प्रोजेक्ट बनाएं। इसका उपयोग सीसी.NET

  2. आउटपुट डीएलएल का नाम * सीसीनेट से मिलान करने की आवश्यकता है। * * CruiseControl.plugin *। प्रोजेक्ट गुणों पर जाएं और * असेंबली नाम "को * सीसीनेट में बदलें। < डालने नाम यहाँ > .CruiseControl.plugin *

  3. अपनी परियोजना में, CC.NET सर्वर स्थापना निर्देशिका में पाया तीन विधानसभाओं के संदर्भ जोड़ (डिफ़ॉल्ट है: C: \ Program Files \ CruiseControl.NET \ सर्वर) :
    • NetReflector.dll
    • ThoughtWorks.CruiseControl.Core.dll
    • ThoughtWorks.CruiseControl.Remote.dll

  4. इस जैसे एक नया सार्वजनिक वर्ग बनाएँ:
     
    using ThoughtWorks.CruiseControl.Core; 
    using ThoughtWorks.CruiseControl.Remote; 
    
    // this is the labeller name that will be used in ccnet.config 
    [ReflectorType("customLabeller")] 
    public class CustomLabeller : ILabeller 
    { 
    [ReflectorProperty("syncronisationFilePath", Required = true)] 
    public string SyncronisationFilePath { get; set; } 
    
    #region ILabeller Members 
    
    public string Generate(IIntegrationResult previousResult) 
    { 
        if (ShouldIncrementLabel(previousResult)) 
        return IncrementLabel(); 
    
        if (previousResult.Status == IntegrationStatus.Unknown) 
        return "0"; 
    
        return previousResult.Label; 
    } 
    
    public void Run(IIntegrationResult result) 
    { 
        result.Label = Generate(result); 
    } 
    
    #endregion 
    
    private string IncrementLabel() 
    { 
        if(!File.Exists(SyncronisationFilePath)) 
        return "0"; 
    
        using (FileStream fileStream = File.Open(SyncronisationFilePath, 
         FileMode.OpenOrCreate, 
         FileAccess.ReadWrite, 
         FileShare.None)) 
        { 
        // read last build number from file 
        var bytes = new byte[fileStream.Length]; 
        fileStream.Read(bytes, 0, bytes.Length); 
    
        string rawBuildNumber = Encoding.ASCII.GetString(bytes); 
    
        // parse last build number 
        int previousBuildNumber = int.Parse(rawBuildNumber); 
        int newBuildNumber = previousBuildNumber + 1; 
    
        // increment build number and write back to file 
        bytes = Encoding.ASCII.GetBytes(newBuildNumber.ToString()); 
    
        fileStream.Seek(0, SeekOrigin.Begin); 
        fileStream.Write(bytes, 0, bytes.Length); 
    
        return newBuildNumber.ToString(); 
        } 
    } 
    
    private static bool ShouldIncrementLabel(IIntegrationResult previousResult) 
    { 
        return (previousResult.Status == IntegrationStatus.Success || 
        previousResult.Status == IntegrationStatus.Unknown) 
    } 
    } 
    


  5. अपनी परियोजना संकलित करें और CC.NET सर्वर स्थापना निर्देशिका के लिए DLL कॉपी (डिफ़ॉल्ट है: C: \ Program Files \ CruiseControl.NET \ सर्वर)

  6. पुनः प्रारंभ CC.NET Windows सेवा

  7. एक पाठ फ़ाइल बनाएँ वर्तमान बिल्ड नंबर

  8. स्टोर करने के लिए
  9. सीसीनेट में प्रोजेक्ट परिभाषा के लिए नया लेबलर जोड़ें।कॉन्फ़िग फ़ाइल:
     
        <labeller type="sharedLabeller"> 
         <syncronisationFilePath>C:\Program Files\CruiseControl.NET\server\shared\buildnumber.txt</syncronisationFilePath> 
    <incrementOnFailure>false</incrementOnFailure> 
        </labeller> 
    
    


3

मैं एक ही मुद्दे में भाग गया, लेकिन मैंने पाया कि <assemblyVersionLabeller> साबित कर दिया के साथ संयोजन के रूप में <stateFileLabeller> का उपयोग कर एक बहुत सरल समाधान किया जाना है।

राज्यफाइललैबेलर का उपयोग करने के बारे में एकमात्र गोचा यह है कि आप किसी प्रोजेक्ट में अपनी राज्य फ़ाइलों के लिए निर्देशिका निर्दिष्ट नहीं कर सकते हैं, क्योंकि CruiseControl.NET इसे नहीं ढूंढ पाएगा। मैंने इसे डिफ़ॉल्ट निर्देशिका में छोड़ा, और यह बहुत अच्छा काम करता है।

3

मैं defaultlabeller की एक प्रतिकृति के अधिक वर्ग अर्नोल्ड बना दिया संशोधित कर लिया है:

using System.IO; 
using System.Text; 

using Exortech.NetReflector; 
using ThoughtWorks.CruiseControl.Core; 
using ThoughtWorks.CruiseControl.Remote; 

// This namespace could be altered and several classes could be put into the same if you'd want to combine several plugins in one dll 
namespace ccnet.SharedLabeller.CruiseControl.plugin 
{ 
    [ReflectorType("sharedLabeller")] 
    public class SharedLabeller : ILabeller 
    { 
     /// <summary> 
     /// The path where the file that holds the shared label should be located 
     /// </summary> 
     /// <default>none</default> 
     [ReflectorProperty("sharedLabelFilePath", Required = true)] 
     public string SharedLabelFilePath { get; set; } 

     /// <summary> 
     /// Any string to be put in front of all labels. 
     /// </summary> 
     [ReflectorProperty("prefix", Required = false)] 
     public string Prefix { get; set; } 

     /// <summary> 
     /// If true, the label will be incremented even if the build fails. Otherwise it will only be incremented if the build succeeds. 
     /// </summary> 
     [ReflectorProperty("incrementOnFailure", Required = false)] 
     public bool IncrementOnFailure { get; set; } 

     /// <summary> 
     /// If false, the label will never be incremented when this project is builded. This is usefull for deployment builds that 
     /// should use the last successfull of two or more builds 
     /// </summary> 
     [ReflectorProperty("increment", Required = false)] 
     public bool Increment { get; set; } 

     /// <summary> 
     /// Allows you to set the initial build number. 
     /// This will only be used when on the first build of a project, meaning that when you change this value, 
     /// you'll have to stop the CCNet service and delete the state file. 
     /// </summary> 
     /// <default>0</default> 
     [ReflectorProperty("initialBuildLabel", Required = false)] 
     public int InitialBuildLabel { get; set; } 

     public SharedLabeller() 
     { 
      IncrementOnFailure = false; 
      Increment = true; 
      InitialBuildLabel = 0; 
     } 

     #region ILabeller Members 

     public string Generate(IIntegrationResult integrationResult) 
     { 
      if (ShouldIncrementLabel(integrationResult.LastIntegration)) 
      { 
       return Prefix + this.GetLabel(); 
      } 
      else 
      { 
       return integrationResult.LastIntegration.Label; 
      } 
     } 

     public void Run(IIntegrationResult integrationResult) 
     { 
      integrationResult.Label = Generate(integrationResult); 
     } 

     #endregion 

     /// <summary> 
     /// Get and increments the label, unless increment is false then it only gets the label 
     /// </summary> 
     /// <returns></returns> 
     private string GetLabel() 
     { 
      ThoughtWorks.CruiseControl.Core.Util.Log.Debug("About to read label file. Filename: {0}", SharedLabelFilePath); 
      using (FileStream fileStream = File.Open(this.SharedLabelFilePath, 
        FileMode.OpenOrCreate, 
        FileAccess.ReadWrite, 
        FileShare.None)) 
      { 
       // Read last build number from file 
       var bytes = new byte[fileStream.Length]; 
       fileStream.Read(bytes, 0, bytes.Length); 

       string rawBuildNumber = Encoding.UTF8.GetString(bytes); 

       // Parse last build number 
       int previousBuildNumber; 
       if (!int.TryParse(rawBuildNumber, out previousBuildNumber)) 
       { 
        previousBuildNumber = InitialBuildLabel - 1; 
       } 

       if (!Increment) 
       { 
        return previousBuildNumber.ToString(); 
       } 

       int newBuildNumber = previousBuildNumber + 1; 

       // Increment build number and write back to file 
       bytes = Encoding.UTF8.GetBytes(newBuildNumber.ToString()); 

       fileStream.Seek(0, SeekOrigin.Begin); 
       fileStream.Write(bytes, 0, bytes.Length); 

       return newBuildNumber.ToString(); 
      } 
     } 

     private bool ShouldIncrementLabel(IntegrationSummary integrationSummary) 
     { 
      return integrationSummary == null || integrationSummary.Status == IntegrationStatus.Success || IncrementOnFailure; 
     } 
    } 
} 

लाभ होना चाहिए कि आप अब उपसर्ग के साथ-साथ "incrementonfailure" निर्दिष्ट कर सकते हैं। इसके अलावा मैंने एक "वृद्धि" संपत्ति भी जोड़ दी है जिसका उपयोग तैनाती के निर्माण के लिए किया जा सकता है जो कि बिल्ड नंबर को बढ़ाना नहीं चाहिए। यदि आप इसे स्वयं संशोधित करना चाहते हैं तो मैं उनके कार्यान्वयन पर विचार करने की सलाह दूंगा: CruiseControl.NET repository folder containing labellers

+0

अच्छा! वोट दिया –