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. 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("ContextScript");<br><br>// Great, now let's dig out the SVN or Perforce changeset
<br>int getMaxChangeSet(BuildLife life) {<br> int result = 0;<br><br> ChangeLog[] changelogArray = ChangeLogHelper.getChangeLogArray(life);<br> for (int i = 0; i < changelogArray.length; i++) {<br> ChangeSet[] changesetArray = changelogArray[i].getChangeSetArray();
<br> for (int j = 0; j < changesetArray.length; j++) {<br> ChangeSet changeset = changesetArray[j];<br> id = changeset.getId();<br> // edit out the "r" character for svn<br> if (id.startsWith
("r")) {<br> id = id.substring(1);<br> }<br> int num = (new Integer(id.trim())).intValue();<br> if (num > result) {<br> result = num;<br> }<br> }<br> }<br> 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 && life != null) {<br> highestChangeset = getMaxChangeSet(life);<br> life = life.getPrevBuildLife();<br>}<br><br>stampContext.put("changeset", ""+highestChangeset);
<br><br><br><div><span class="gmail_quote">On 1/22/08, <b class="gmail_sendername">Chou, David</b> <<a href="mailto:[email protected]">[email protected]</a>> 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> </p>
<p>Is there a way to 'stamp' the build with the SVN
revision number that the build was checked out as?</p>
<p> </p>
<p>Or is there another way that's easier?</p>
<p> </p>
<p>-- David</p>
<p> </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==--