{"id":112,"date":"2011-01-30T03:19:31","date_gmt":"2011-01-30T03:19:31","guid":{"rendered":"http:\/\/thewiredguy.com\/wordpress\/?p=112"},"modified":"2011-01-30T03:19:31","modified_gmt":"2011-01-30T03:19:31","slug":"generate-cruisecontrol-net-build-report-in-powershell","status":"publish","type":"post","link":"https:\/\/inullable.in\/blog\/?p=112","title":{"rendered":"Generate CruiseControl.Net Build Report in Powershell"},"content":{"rendered":"<p>Recently, I wanted to generate report of all the builds happening on my system. I came up with a very simple solution using Powershell script.<\/p>\n<p>If you look at the CC.Net directory structure, you can find that all the project specific logs are kept at &lt;CC.Net&gt;server&lt;project-name&gt;ArtifactsBuildLogs (in Default config)<\/p>\n<p>So, if you have a project named MyFirstProject&#8230;<\/p>\n<p>it will be in the &lt;CC.Net&gt;serverMyFirstProjectArtifactsBuildLogs<\/p>\n<p><span style=\"font-size: 13px; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px;\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-115\" title=\"dir\" src=\"http:\/\/thewiredguy.com\/wordpress\/wp-content\/uploads\/2011\/01\/dir.gif\" alt=\"\" width=\"247\" height=\"322\" \/><\/span><\/p>\n<p><span style=\"font-size: 13px; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px;\"> <\/span>further the log files names also follow a pattern<\/p>\n<p>for example, take this:<\/p>\n<p>log20101125115243Lbuild.4.xml<\/p>\n<p>this consists of log+&lt;year&gt;+&lt;month&gt;+&lt;day&gt;+&lt;hour&gt;+&lt;min&gt;+&lt;sec&gt;+LBuild.&lt;build-label&gt;.xml, so from the file name above, we can know that:<\/p>\n<p>Year = 2010, month = 11, day= 25; hour = 11, min = 52, sec = 43.<\/p>\n<p>If build had failed, then the file name changes to :<\/p>\n<p>log+&lt;year&gt;+&lt;month&gt;+&lt;day&gt;+&lt;hour&gt;+&lt;min&gt;+&lt;sec&gt;.xml, that is the Build-Label is missing.<\/p>\n<p>So I quickly wrote this powershell script, which spits out results as CSV.<\/p>\n<p>Project Name, Date of Build, Build-Label, Status<\/p>\n<p><strong>_____________________________________________________________<\/strong><\/p>\n<pre style=\"color: black; background: #ffffff; width: 600px; margin: 0px; padding: 5px; border: 2px;\"><code><label>\n$Currentdate = get-date -uformat  \"%m\"\nif( $Currentdate -contains \"01\") # first month of Year\n{\n      $Currentdate = get-date -uformat  \"%Y%m\"\n      $date = $Currentdate -89   #go to last month of previous year\n}\nelse # not first month of Year\n{\n      $Currentdate = get-date -uformat  \"%Y%m\"\n      $date = $Currentdate -1\n}\nwrite(\"Project,date,label,status\") &gt; D:file.csv\ncls\nD:        # ---- CruiseControl.NET Installation drive ----\ncd  \"D:CruiseControl.netserver\"\ncls\n\n$proj = get-childitem\nforeach( $file in $proj)\n{\n    if($file.length -lt 0)\n    {\n        $file.Name\n        push-location\n        if($file.Name -ne \"xsl\" )\n        {\n                                 #$file.Name: This is the project name\n                                 cd $file.name\n                                 cd Artifacts\n                                 cd buildlogs\n\n\t\t\t\t$xmls = get-childitem #-Include log$date*build.*.xml\n\t\t\t\tforeach($xmlfile in $xmls)\n\t\t\t\t{\n\t\t\t\t            $pattern = \"log.*LBuild.(?<label>.*).xml\"\n\t\t\t\t                                             $success = $xmlfile -match $pattern\n\t\t\t\t                                             if($matches -and $matches['label'])\n                                       \t\t\t\t            {\n\t\t\t\t                                                 write($file.Name + \" , \"+ $file.LastWriteTime + \" , \"+ $matches[\"label\"] +\" , Success\")&gt;&gt; D:file.csv\n\t\t\t\t                                                 del variable:matches\n                                 \t\t\t\t            }\n\t\t\t\t                                           else\n\t\t\t\t\t\t\t                   {\n                                                                                 write($file.Name + \" , \"+ $file.LastWriteTime + \" , NA , Failed\") &gt;&gt; D:file.csv\n\t\t\t\t\t\t                           }\n\n                                              \t\t\t\tcmd \/c pause\n        \t\t                              }\n                                                     pop-location\n\t\t}\n\t}\n}\n<\/label><\/label><\/code><\/pre>\n<p><strong>___________________________________________________________<\/strong><\/p>\n<p>Hmm&#8230; Powershell is really powerful \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I wanted to generate report of all the builds happening on my system. I came up with a very simple solution using Powershell script. If you look at the CC.Net directory structure, you can find that all the project specific logs are kept at &lt;CC.Net&gt;server&lt;project-name&gt;ArtifactsBuildLogs (in Default config) So, if you have a project [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[111,221],"tags":[],"_links":{"self":[{"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/posts\/112"}],"collection":[{"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=112"}],"version-history":[{"count":0,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions"}],"wp:attachment":[{"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}