Get source from a label

Topics: Developer Forum, User Forum
Jul 3, 2007 at 4:40 PM
Edited Jul 3, 2007 at 5:02 PM
Instead of using ApplyLabel to attach a label to the latest after a checkout, I would like to get the source from a label. I've added alternate properties on the CCNET plugin to accept this:
<vsts autoGetSource="true" applyLabel="true">
<server>http://dwtbi1:8080</server>
<username>&portalbuilduser;</username>
<password>&portalbuildpassword;</password>
<domain>MY_DOMAIN</domain>
<project>$/Portal</project>
<workingDirectory>&portalbuildfromlabelworking_directory;</workingDirectory>
<cleanCopy>true</cleanCopy>
<workspace>&build_server;</workspace>
<deleteWorkspace>false</deleteWorkspace>
<labelFullPath>&buildpublishpath;/portalbuildfromlabelversion.txt</labelFullPath>
</vsts>

I'm using labelFullPath to indicate a file the will store the label name to retreive.

I'd like to modify GetSource to use the label instead of just the latest.

I thought something like this might work:
Log.Debug("Examine label from file: " + LabelFullPath);
StreamReader streamReader = new StreamReader(LabelFullPath);
String labelName = streamReader.ReadToEnd().Trim();
streamReader.Close();
Log.Debug("Query label: " + labelName);
VersionControlLabel[] versionControlLabels =
this.SourceControl.QueryLabels(labelName, ProjectPath, null, false);
foreach (VersionControlLabel versionControlLabel in versionControlLabels)
{
Log.Debug("Extracting from label: " + versionControlLabel.Name);
foreach (Item item in versionControlLabel.Items)
{
Log.Debug("Download item: " + item.ArtifactUri.AbsolutePath);
GetRequest getReq =
new GetRequest(new ItemSpec(ProjectPath, RecursionType.Full), item.ChangesetId);
if (CleanCopy)
{
Log.Debug("Forcing a Get Specific with the options \"get all files\" and \"overwrite read/write files\"");
workspace.Get(getReq, GetOptions.GetAll | GetOptions.Overwrite);
}
else
{
Log.Debug("Performing a Get Latest");
workspace.Get(getReq, GetOptions.None);
}
}
}

But nothing happens. I mean I don't get an invalid label exception, at least that's something...

Are there any C# examples out there on how to use QueryLabel to get a label and then get that source?

Really I'd like the equivalent of this:

GetRequest getReq = new GetRequest(new ItemSpec(ProjectPath, RecursionType.Full), LatestVersionSpec.Instance);

to get a label.

Essentially something like this:

GetRequest getReq = new GetRequest(new ItemSpec(ProjectPath, RecursionType.Full), Microsoft.TeamFoundation.VersionControl.Client.LabelItemSpec.Instance);

Somehow the label name has to be used to get the instance of LabelItemSpec....

Why doesn't VersionControlLabel have a reference to LabelItemSpec?
Jul 4, 2007 at 4:58 PM
Can you not just do something like:-

GetRequest getReq = new GetRequest(new ItemSpec(ProjectPath, RecursionType.Full), new LatestVersionSpec("My label"));

Once you've got the get working, might want to figure out a way of checking if the label has been modified during the start_end dates specified by cruise control - i.e. take a look at the LastModifiedDate on the VersionControlLabel object and see if it is within the period passed by CruiseControl. That way, build will only be kicked off when that label had been modified (i.e. by adding a new file to it). Note, that there are other ways of modifing a label (such as editing the comment etc) so this might not do exactly what you want, but might be a good start.

Good luck, let me know how you get on.

M.
Jul 4, 2007 at 7:59 PM
I have a more simple check. Each time I checkout a label, it gets built, and a MSI is created. So I'll just check if that MSI exists before returning modifications.
Jul 5, 2007 at 5:30 PM
This worked:

GetRequest getReq = new GetRequest(new ItemSpec(ProjectPath, RecursionType.Full), new LabelVersionSpec(labelName));
Jul 30, 2007 at 10:03 PM
Has this code been committed to the project now? This is something I could really start using today.
Jul 30, 2007 at 11:31 PM
Edited Jul 30, 2007 at 11:33 PM
Here is my version that has been working well for me:
http://www.tagenigma.com/qa/Vsts.cs
Jul 30, 2007 at 11:36 PM
Edited Jul 30, 2007 at 11:41 PM
This is the xml that I have been testing with:

<!ENTITY build_user "dgfdgfdbvcb">



<sourcecontrol type="multi">
<sourceControls>
<vsts autoGetSource="true" applyLabel="true">
<server>http://dwtbi1:8080</server>
<username>&build_user;</username>
<password>&build_password;</password>
<domain>dfsdfds</domain>
<project>$/dfsgdfgfdg</project>
<workingDirectory>&buildfromlabelworkingdirectory;</workingDirectory>
<cleanCopy>true</cleanCopy>
<workspace>&build_server;</workspace>
<deleteWorkspace>false</deleteWorkspace>
<labelFullPath>&buildpublishpath;/buildfromlabel_version.txt</labelFullPath>
<labelPrefix>&build_server;-fdsfdsfdsfsd-</labelPrefix>
<publishPath>&buildversionpath;</publishPath>
</vsts>
</sourceControls>
</sourcecontrol>
Jul 31, 2007 at 6:11 PM
Edited Jul 31, 2007 at 6:38 PM

tgraupmann wrote:
Here is my version that has been working well for me:
http://www.tagenigma.com/qa/Vsts.cs


Awesome. Thank you.
I had an error with the file before I copied you modifications into it. It was :"AddIntegrationProperty" build failure on ThoughtWorks.CruiseControl.Core.IIntegrationResults. This could be fixed by simply using the "Add" method on the IntegrationResults dictionary property itself. Odd.

Your code compiles just fine though. I'm going to try it out.