title: Want to create an object in groovy to collect Jenkins pipeline stage data
body: <p>I want to create a Jenkins pipeline report and want to send that report via Email.</p>
  <p>Requirements:</p>
  <ul>
  <li>The report must have information about each separate stage.</li>
  <li>I want to create a class named Report, which contains a structure having methods to add and read report data from each stage.</li>
  <li>Create a single object for every stage that contains report data from each stage. Report data can be of MAP, String, or List.</li>
  </ul>
  <p>EX:</p>
  <pre><code>pipeline(postBuild: {})
  { Stage(&quot;stage1&quot;){echo hello}
    Stage(&quot;stage2&quot;){echo from}
    Stage(&quot;stage3&quot;){echo groovy}
    Stage(&quot;stage4&quot;){echo and jenkins}
  }
  </code></pre>
  <p>What I did is created a class name Report</p>
  <pre><code>@Singleton(lazy=true)
  @ToString(includeNames=true, includeFields=true)
  class Report {
      //  Will be collecting stage name and summary
      def stageName;
      def stageReport;
      def result;
  
      //method to set value
      def addStageReport(stageName, stageReport) {
          this.stageName = stageName;
          this.stageReport = stageReport;
          result.append(stageName);
          result.append(stageReport);
      }
  
      // method to get value
      def readStageReport() {
          return result;
      }
  }
  </code></pre>
  <p>and I am creating an object of Report class to store each stage information</p>
  <pre><code>    pipeline(postBuild: {sendReport(report)}) //this will create report from data in report object and email to the user
      { 
        Stage('Check'){
        echo Checking
        Map stageName[&quot;Name&quot;:&quot;check&quot;]
        Map stageReport[&quot;Result&quot;:&quot;success&quot;]
        report.addStageReport(stageName, stageReport)
        }
        Stage('validate'){echo validating}
        Stage('build'){echo building}
        Stage(&quot;test&quot;){echo testing}
      }
       ```
  </code></pre>