none
TFS 2013 Workspace

    Question

  • I am trying to assign a local process template variable the value of the current build workspace. The GetWorkspace activity takes a name, but I cannot locate the name of the currently building workspace.

    Tuesday, October 01, 2013 6:53 PM

Answers

  • Hi Keith. I asked our team build devs about this and unfortunately, this a bit harder now. We've simplified the templates and exposed fewer details on how things get done and this is just a consequence of that. You can continue to use the version 11 templates if you like, or create a Workspace object from the local path. Jason Prickett (one of the aforementioned devs) suggested this could be done in an Assign activity with an expression like this (not tested - could be typos)…

    // First get SourcesDirectory
    <mtbac:GetEnvironmentVariable x:TypeArguments="x:String" Name="SourcesDirectory" Result="srcDir"/>
    // Then get IBuildDetail
    <mtbac:GetEnvironmentVariable x:TypeArguments="mtbc:IBuildDetail" Name="BuildDetail" Result="build"/>
    // Finally get the workspace
    <Assign x:TypeArguments="mtvc:Workspace" To="workspace"
    Value="[build.BuildServer.TeamProjectCollection.GetService<VersionControlServer>().GetWorkspace(srcDir)]" />


    Trevor Hancock (Microsoft)
    Please remember to "Mark As Answer" the replies that help.

    Thursday, October 03, 2013 6:55 PM

All replies

  • Hi Keith, 

    Thanks for your post.

    What’s do you want to achieve?

    Please provide the detailed reproduce steps here, I will follow your steps to reproduce this scenario and try to provide the better response.


    John Qiao [MSFT]
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 02, 2013 6:25 AM
  • Well, the purpose is to get the Sonar activity working from the TFS community extensions.

    One required argument is "BuildWorkspace", so I need to pass in the Workspace. I tried using the GetWorkspace activity, but it requires a Workspace name, and I cannot find that value.

    I just need a reference to the currently building workspace.

    Wednesday, October 02, 2013 1:55 PM
  • Hi Keith,  

    Thanks for your reply.

    In the Run On Agent scope of build process template, there have two predefined/default Workspace and WorkspaceName variables, you can use these two variables in your activity directly. The value for Workspace is workspacename;domain\user, the value for WorkspaceName is workspacename. 

    For more information about this TFS Community Extensions activity, please create a new thread about this issue in TFS Community Build Extensions Discussions site for the better response.


    John Qiao [MSFT]
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, October 03, 2013 3:33 AM
  • John, thanks for the reply. You are correct if you are talking about TFS 2012, however, those variables do not exist inside of the default template for 2013, which is why I am pulling out my hair.

    The reason I made the post here is because since this is primarily about TFS 2013, and how to access the variable that used to be commonly available in TFS 2012.

    Again, this is the DefaultTemplate for 2013, not Lab

    Thursday, October 03, 2013 11:48 AM
  • Hi Keith. I asked our team build devs about this and unfortunately, this a bit harder now. We've simplified the templates and exposed fewer details on how things get done and this is just a consequence of that. You can continue to use the version 11 templates if you like, or create a Workspace object from the local path. Jason Prickett (one of the aforementioned devs) suggested this could be done in an Assign activity with an expression like this (not tested - could be typos)…

    // First get SourcesDirectory
    <mtbac:GetEnvironmentVariable x:TypeArguments="x:String" Name="SourcesDirectory" Result="srcDir"/>
    // Then get IBuildDetail
    <mtbac:GetEnvironmentVariable x:TypeArguments="mtbc:IBuildDetail" Name="BuildDetail" Result="build"/>
    // Finally get the workspace
    <Assign x:TypeArguments="mtvc:Workspace" To="workspace"
    Value="[build.BuildServer.TeamProjectCollection.GetService<VersionControlServer>().GetWorkspace(srcDir)]" />


    Trevor Hancock (Microsoft)
    Please remember to "Mark As Answer" the replies that help.

    Thursday, October 03, 2013 6:55 PM
  • hi,

    i have the same problem and try to solve it with the sample from Trevor Hancock.

    but, it's not running. on compiling i get a exception.

    exception translated by google:

    The extension "Microsoft.Activities.Build.Validation.ValidationBuildExtension" has an exception of type 'System.Xaml.XamlObjectWriterException ":" Failed to create "Result" from the text "srcdir". "caused.

    i need a solution in this case. to use the template from tfs2012 is not welcome. can anybody help me?

    byby andy

    Thursday, November 14, 2013 9:04 AM
  • Did anyone ever nail this?  I'm trying to get the current Workspace object also....
    Tuesday, February 04, 2014 6:08 PM
  • I'm also looking for a fix for this. The SourcesDirectory does not exist in the TfvcTemplate.12.xaml template. Since nearly every non-Microsoft custom code activity use things like Workspace and BuildDetail, it seems like the community is being left in the dark. Epic.

    Again, this is the default build process template in TFS 2013, NOT 2012, build template. TFS Community Extensions, Nugetter, and TfsVersioning will all be very negatively impacted without either some clarification or solution.

    Some general advise to anyone with any sort of build customization who is considering an upgrade to TFS 2013 - DON'T. 

    FWIW, you get the SourcesDirectory through Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.SourcesDirectory

    Also, the above suggestion got me on the right path with a minor correction:
    build.BuildServer.TeamProjectCollection.GetService(Of VersionControlServer).GetWorkspace(srcDir)
    • Edited by JamesDMiera Friday, February 14, 2014 1:56 AM
    Friday, February 14, 2014 1:38 AM
  • Hi JamesDMiera,

    If I understand you, this means to create a GetEnvironmentVariable<T> node of Microsoft.TeamFoundation.VersionControl.Client.Workspace type?and in the expression to put:

    build.BuildServer.TeamProjectCollection.GetService(Of VersionControlServer).GetWorkspace(srcDir)

    I also guess srcDir is a string set before of this node, but I'm getting that BuildServer is not a member of Build. I also had to add Microsoft.TeamFoundation.Client to the imports of the .xaml file.

    Please let me know if you have found more info on this. I'm trying to make the TFS Versioning extension work, but no luck so far.

    If anybody else have found any way to populate a Workspace object correctly, please let us know too. This was a very useful feature used in so many build process customizations in TFS 2012 that is hard to understand why it was removed.


    • Edited by alexitosrv2 Tuesday, March 11, 2014 2:22 PM
    Tuesday, March 11, 2014 12:40 AM
  • Try this:

    https://tfsversioning.codeplex.com/discussions/465193#post1250973

    • Proposed as answer by Saeid Moos Sunday, August 03, 2014 5:33 AM
    Thursday, May 29, 2014 6:49 PM
  • Or just create a simple code activity:

    using System.Activities;
    using Microsoft.TeamFoundation;
    using Microsoft.TeamFoundation.Build.Activities.Extensions;
    using Microsoft.TeamFoundation.Build.Client;
    using Microsoft.TeamFoundation.Build.Workflow.Activities;
    
    namespace Tosan.TeamFoundation.Build.Activities
    {
        public class GetDefaultWorkSpaceName : CodeActivity
        {
            public OutArgument<string> Result { get; set; }
            protected override void Execute(CodeActivityContext activityContext)
            {
                var environmentVariableExtension = activityContext.GetExtension<IEnvironmentVariableExtension>();
                var buildDetail = environmentVariableExtension.GetEnvironmentVariable<IBuildDetail>(activityContext, WellKnownEnvironmentVariables.BuildDetail);
                var buildAgent = environmentVariableExtension.GetEnvironmentVariable<IBuildAgent>(activityContext, WellKnownEnvironmentVariables.BuildAgent);
    
                var buildDefinitionId = buildDetail.BuildDefinition.Id;
                var toolSpecificId = LinkingUtilities.DecodeUri(buildAgent.Uri.AbsoluteUri).ToolSpecificId;
                var serviceHostname = buildAgent.ServiceHost.Name;
    
                Result.Set(activityContext, string.Format("{0}_{1}_{2}", new object[] { buildDefinitionId, toolSpecificId, serviceHostname }));
            }
    
        }
    }


    • Edited by Saeid Moos Sunday, August 03, 2014 5:38 AM
    Sunday, August 03, 2014 5:35 AM