【问题标题】:How to Label Source upon successful build on Visual Studio Team Services如何在 Visual Studio Team Services 上成功构建后标记源
【发布时间】:2015-11-28 13:03:30
【问题描述】:

我试图在 Visual Studio Team Services(不是 XAML)上使用新的构建,但无法弄清楚如何在成功构建后标记源。有什么想法吗?

下面是显示如何在 XAML 中执行的屏幕截图。

我已经在https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/9613014-allow-label-source-upon-succesful-build-on-visual 提出了功能请求,我实际上是在寻求解决方法,直到 Microsoft 实施它。

【问题讨论】:

    标签: visual-studio msbuild azure-devops azure-pipelines


    【解决方案1】:

    标签源功能在 vNext 版本中不可用。

    除了标签源功能之外,关联工作项和在构建失败时创建工作项功能也不可用。

    您可以在 Microsoft UserVoice 网站上提交一项关于它的功能请求:https://visualstudio.uservoice.com/forums/121579-visual-studio/category/30925-team-foundation-server-visual-studio-online

    【讨论】:

    • 谢谢 Vicky,我已经向 UserVoice 发帖,实际上是在寻找解决方法。感谢您的宝贵时间!
    【解决方案2】:

    我刚刚注意到该功能现在可以在 build vNext 中使用。它的配置位于构建定义的 Repository 选项卡中。

    【讨论】:

    • 对不起,不能发图片,我的声望太低了:-(
    • @cilerler:已用截图编辑!
    • 但是你如何使用这个字段呢?无论我在此字段中输入什么内容,都会收到一条错误消息,指出“源标签格式无效:”。我什至输入了您在屏幕截图中输入的内容,但仍然出现错误。我找不到指向可以在该字段中使用哪些变量的文档。任何帮助将不胜感激。
    • @GregVeres 尝试类似$(Build.DefinitionName)_$(Build.DefinitionVersion)_$(Build.BuildId)_$(Build.BuildNumber)_$(My.Variable)(来自visualstudio.com/en-us/docs/build/define/repository#
    【解决方案3】:

    对于那些在此线程中运行并寻找 TFS 托管(不是 VSO)解决方案的人,请注意 TFS 2015 更新 1 中提供了对构建标签的支持:https://www.visualstudio.com/en-us/news/tfs2015-update1-vs.aspx

    我们还没有运行更新 1,所以我无法确认。

    编辑:我们现在正在运行更新 1(实际上是更新 2),标签构建源适用于本地。

    【讨论】:

    • 我们正在运行本地 TFS 2015 更新 1,并且该功能已存在。
    【解决方案4】:

    我认为 Yves Dierick 在 2015 年 10 月的回答是正确的,但从那时起 VSTS 屏幕的布局发生了很大变化。在最新版本(截至 2017 年 2 月)中,您可以通过选择 Build Definition 中的 Get Sources 任务,选择右上角的 show Advanced Settings 来为成功的构建添加标签,然后在出现的标记源部分下选择成功单选按钮。

    我花了一段时间才找到它,所以我认为它可能对其他人有帮助。此选项位于“标记来源”下并且根本没有提及“标签”一词,这无济于事。


    2018 年 3 月 13 日更新

    他们再次调整了此页面的布局,但如果有的话让它变得更简单,现在该选项被命名为“标签来源”更有用。

    【讨论】:

    • 看来,他们再次更改了布局并将其移到了我找不到的地方。
    • 实际上我认为他们现在让它变得更简单了。它仍然与我上面的屏幕截图中的位置相同,但高级设置滑块似乎已经消失。只需确保您在左侧选择了 Get Sources 任务即可。
    【解决方案5】:

    XAML 构建在构建开始时标记了源,而 vNext 构建似乎在构建结束时标记。 我注意到了,因为我在构建过程中修改/签入/标签文件。 如果我让 vNext 标记构建,它会将我在签入后应用于文件的标签移动到以前的版本(在 GetSources 中使用的版本)。

    但我没有在任何日志文件中看到 vNext 的标签。我错过了吗? 我将不得不在 vnext 中禁用标签并在我的 msbuild 脚本中执行此操作...

    编辑: 在 vnext 构建定义中禁用标签并创建一个 msbuild 内联任务来标记工作区的源。现在我可以在构建开始时标记所有源,并为在构建期间修改的文件移动标签:)

    如果有人想做类似的事情,这是我的内联任务:

    <!--
        TaskName="LabelWorkspaceSources"
        - input: TfexeFullPath is the path to tf.exe
        - input: BaseDirectory is the mapped folder of the software to build
        - input: Label to apply
        - input: Version is the changeset to apply the label to
    -->
    <UsingTask TaskName="LabelWorkspaceSources" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
        <ParameterGroup>
            <TfexeFullPath Required="true" />
            <BaseDirectory Required="true" />
            <Label Required="true" />
            <Version Required="true" />
        </ParameterGroup>
        <Task>
            <Code Type="Fragment" Language="cs">
            <![CDATA[
    
            //--- get the workspace mapping ---
    
            System.Diagnostics.Process tfProcess = new System.Diagnostics.Process();
            tfProcess.StartInfo.FileName = TfexeFullPath;
            tfProcess.StartInfo.Arguments = "workfold";
            tfProcess.StartInfo.UseShellExecute = false;
            tfProcess.StartInfo.CreateNoWindow = true;
            tfProcess.StartInfo.RedirectStandardOutput = true;
            tfProcess.StartInfo.WorkingDirectory = BaseDirectory;
            tfProcess.Start();
    
            string output = tfProcess.StandardOutput.ReadToEnd();
    
            tfProcess.WaitForExit();
    
            string workfoldOutput = output.Trim();
            Log.LogMessage(workfoldOutput, MessageImportance.High);
    
            string[] linesWorkfoldOutput = workfoldOutput.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            List<string> mappedFolders = new List<string>();
    
            Log.LogMessage("Trying to parse mapped folders.", MessageImportance.High);
            foreach (string line in linesWorkfoldOutput)
            {
                //e.g. $/TPA: C:\TFS_Source\TPA
                if (line.Contains("$/"))
                {
                    string[] lineSplit = line.Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries);
    
                    //entry lineSplit[0] now contains the server path, lineSplit[1] contains the local folder
                    mappedFolders.Add(lineSplit[1]);
                    Log.LogMessage("Found mapped folder: " + lineSplit[1], MessageImportance.High);
                }
            }
    
    
            //--- label all the mapped folders ---
    
            foreach (string mappedFolder in mappedFolders)
            {
                tfProcess = new System.Diagnostics.Process();
                tfProcess.StartInfo.FileName = TfexeFullPath;
                tfProcess.StartInfo.Arguments = "label " + Label + " \"" + mappedFolder + "\" /child:replace /recursive /comment:\"Label created by task LabelWorkspaceSources\" /version:" + Version;
                tfProcess.StartInfo.UseShellExecute = false;
                tfProcess.StartInfo.CreateNoWindow = true;
                tfProcess.StartInfo.RedirectStandardOutput = true;
                tfProcess.StartInfo.WorkingDirectory = mappedFolder;
                tfProcess.Start();
    
                output = tfProcess.StandardOutput.ReadToEnd();
    
                tfProcess.WaitForExit();
    
                Log.LogMessage(tfProcess.StartInfo.Arguments, MessageImportance.High);
                Log.LogMessage(output, MessageImportance.High);
            }
            ]]>
            </Code>
        </Task>
    </UsingTask>
    

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 1970-01-01
      • 2017-06-29
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2016-08-14
      • 1970-01-01
      相关资源
      最近更新 更多