Re: SVN Revision number as stamp

"Steve Boone" <[email protected]> Tue, 22 Jan 2008 13:54:22 -0500
Newsgroups gmane.comp.java.anthill
Message-ID <[email protected]>
--===============0725882849==
Content-Type: multipart/alternative; 
	boundary="----=_Part_12019_25851431.1201028063033"

------=_Part_12019_25851431.1201028063033
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

David,

This script should work for you.  Set this as a stamp scontect script, and
then configure your workflow to refer to this script to determine the stamp.



import com.urbancode.anthill3.domain.singleton.serversettings.*;
import com.urbancode.anthill3.domain.buildlife.*;
import com.urbancode.anthill3.domain.jobtrace.*;
import com.urbancode.anthill3.domain.jobtrace.buildlife.*;
import com.urbancode.anthill3.runtime.scripting.helpers.*;
import com.urbancode.commons.xml.DOMUtils;
import com.urbancode.vcsdriver3.*;

private org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger
("ContextScript");

// Great, now let's dig out the SVN or Perforce changeset
int getMaxChangeSet(BuildLife life) {
  int result = 0;

  ChangeLog[] changelogArray = ChangeLogHelper.getChangeLogArray(life);
  for (int i = 0; i < changelogArray.length; i++) {
    ChangeSet[] changesetArray = changelogArray[i].getChangeSetArray();
    for (int j = 0; j < changesetArray.length; j++) {
      ChangeSet changeset = changesetArray[j];
      id = changeset.getId();
      // edit out the "r" character for svn
      if (id.startsWith("r")) {
        id = id.substring(1);
      }
      int num = (new Integer(id.trim())).intValue();
      if (num > result) {
        result = num;
      }
    }
  }
  return result;
}

// If there is no changelog, look up the previous build
// and take the highest number from that (if present, else keep searching).
int highestChangeset = 0;
BuildLife life = BuildLifeLookup.getCurrent();
while(highestChangeset == 0 && life != null) {
  highestChangeset = getMaxChangeSet(life);
  life = life.getPrevBuildLife();
}

stampContext.put("changeset", ""+highestChangeset);


On 1/22/08, Chou, David <[email protected]> wrote:
>
>  For setting up a continuous integration builds workflow I would like to
> be able to identify my builds by SVN revision numbers to make them more
> distinguishable than the global Build Life numbers.
>
>
>
> Is there a way to 'stamp' the build with the SVN revision number that the
> build was checked out as?
>
>
>
> Or is there another way that's easier?
>
>
>
> -- David
>
>
>
> _______________________________________________
> Anthill mailing list
> Anthill-IWHQxnLZ/[email protected]
> http://lists.urbancode.com/mailman/listinfo/anthill
>
>

------=_Part_12019_25851431.1201028063033
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

David,<br><br>This script should work for you.&nbsp; Set this as a stamp scontect script, and then configure your workflow to refer to this script to determine the stamp.<br><br><br><br>import com.urbancode.anthill3.domain.singleton.serversettings.*
;<br>import com.urbancode.anthill3.domain.buildlife.*;<br>import com.urbancode.anthill3.domain.jobtrace.*;<br>import com.urbancode.anthill3.domain.jobtrace.buildlife.*;<br>import com.urbancode.anthill3.runtime.scripting.helpers.*
;<br>import com.urbancode.commons.xml.DOMUtils;<br>import com.urbancode.vcsdriver3.*;<br><br>private org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(&quot;ContextScript&quot;);<br><br>// Great, now let&#39;s dig out the SVN or Perforce changeset
<br>int getMaxChangeSet(BuildLife life) {<br>&nbsp; int result = 0;<br><br>&nbsp; ChangeLog[] changelogArray = ChangeLogHelper.getChangeLogArray(life);<br>&nbsp; for (int i = 0; i &lt; changelogArray.length; i++) {<br>&nbsp;&nbsp;&nbsp; ChangeSet[] changesetArray = changelogArray[i].getChangeSetArray();
<br>&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; changesetArray.length; j++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ChangeSet changeset = changesetArray[j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id = changeset.getId();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // edit out the &quot;r&quot; character for svn<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (id.startsWith
(&quot;r&quot;)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id = id.substring(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int num = (new Integer(id.trim())).intValue();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (num &gt; result) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = num;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>&nbsp; return result;
<br>}<br><br>// If there is no changelog, look up the previous build<br>// and take the highest number from that (if present, else keep searching).<br>int highestChangeset = 0;<br>BuildLife life = BuildLifeLookup.getCurrent
();<br>while(highestChangeset == 0 &amp;&amp; life != null) {<br>&nbsp; highestChangeset = getMaxChangeSet(life);<br>&nbsp; life = life.getPrevBuildLife();<br>}<br><br>stampContext.put(&quot;changeset&quot;, &quot;&quot;+highestChangeset);
<br><br><br><div><span class="gmail_quote">On 1/22/08, <b class="gmail_sendername">Chou, David</b> &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">









<div link="blue" vlink="purple" lang="EN-US">

<div>

<p>For setting up a continuous integration builds workflow I
would like to be able to identify my builds by SVN revision numbers to make
them more distinguishable than the global Build Life numbers.</p>

<p>&nbsp;</p>

<p>Is there a way to 'stamp' the build with the SVN
revision number that the build was checked out as?</p>

<p>&nbsp;</p>

<p>Or is there another way that's easier?</p>

<p>&nbsp;</p>

<p>-- David</p>

<p>&nbsp;</p>

</div>

</div>


<br>_______________________________________________<br>Anthill mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Anthill-IWHQxnLZ/[email protected]">Anthill-IWHQxnLZ/[email protected]</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.urbancode.com/mailman/listinfo/anthill" target="_blank">
http://lists.urbancode.com/mailman/listinfo/anthill</a><br><br></blockquote></div><br>

------=_Part_12019_25851431.1201028063033--

--===============0725882849==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Anthill mailing list
Anthill-IWHQxnLZ/[email protected]
http://lists.urbancode.com/mailman/listinfo/anthill

--===============0725882849==--