【问题标题】:Controlling build task flow in Team Build 2015在 Team Build 2015 中控制构建任务流
【发布时间】:2016-04-23 03:24:37
【问题描述】:

是否可以在 TFS2015 build vNext 中集中控制构建流程?

比如说,我希望在构建之前和之后执行一些业务任务(自定义任务),但不希望用户能够在构建定义编辑器中删除或更改这些任务的位置。

或者有没有办法通过不公开任务来创建构建定义模板来实现相同的目标?

注意:我不想使用 XAML 构建定义,因为它没有新的 xPlat 构建功能等。

【问题讨论】:

  • 我想知道你在说什么样的前/后步骤。听起来好像不是真的要在构建中完成...
  • 作为审计要求的一部分,我想归档源代码并运行一些关于依赖关系的报告,这些是我的业务任务,我不希望用户跳过这个。
  • 由于构建链接到特定的签入/提交,在构建完成后异步生成这些额外的东西不是更容易吗?
  • 并非如此。其中一些需要在构建之前完成,一旦解决了依赖关系并在构建结束时完成

标签: build tfsbuild tfs-2015


【解决方案1】:

不,这是不可能的。如果它们是自定义任务,它们可以设置并检查变量以确保它们以正确的顺序运行,但这是您必须自己实现的。

目前在构建框架或代理基础设施中没有任何东西可以强制或部分指定只能在特定位置扩展的构建模板。

也不可能在工作流程的早期步骤中注册“终结器”之类的东西。

【讨论】:

    【解决方案2】:

    我认为至少应该包含 jessehouwing 所描述的功能。我已经建立了自定义任务来做到这一点,我希望有一个计划,但 MS 没有足够的时间来解决这个问题。包含任务的来源可在:https://github.com/Microsoft/vsts-tasks/tree/master/Tasks

    这是一篇很好的参考文章: http://www.colinsalmcorner.com/post/developing-a-custom-build-vnext-task-part-1

    我获取了 CmdLine 源并对其进行了修改以包含 If Condition 属性。我创建了一个默认值为 false 的构建变量,并勾选了 Allow at Queue Time,然后将该变量放入任务的 If Condition 属性中。我修改了powershell脚本:

    If ($ifCondition -eq "true" -Or $ifCondition -eq "True" -Or $ifCondition -eq 1 -Or $ifCondition -eq -1)
    {
        Write-Host "Creating process"
        ...
    }
    

    当我对构建进行排队时,如果我将变量更改为 1、-1、true 或 True,则流程会执行;否则它不会。

    task.json

    {
      "id": "3A056A74-E34F-4767-8DCD-3F9461F4BCEC",<<<---BE SURE TO CHANGE THIS
      "name": "CmdLineEx",
      "friendlyName": "Command Line Ex (Conditional)",
      "description": "Run a command line with arguments",
      "helpMarkDown": "[More Information](http://go.microsoft.com/fwlink/?LinkID=613735)",
      "category": "Utility",
      "visibility": [
        "Build",
        "Release"
      ],
      "author": "Microsoft Corporation",
      "version": {
        "Major": 1,
        "Minor": 0,
        "Patch": 22
      },
      "groups": [
        {
          "name": "advanced",
          "displayName": "Advanced",
          "isExpanded": false
        }
      ],
      "inputs": [
        {
          "name": "filename",
          "type": "string",
          "label": "Tool",
          "defaultValue": "",
          "required": true,
          "helpMarkDown": "Tool name to run.  Tool should be found in your path.  Optionally, a fully qualified path can be supplied but that relies on that being present on the agent.<br/> Note: You can use **$(Build.SourcesDirectory)**\\\\ if you want the path relative to repo."
        },
        {
          "name": "arguments",
          "type": "string",
          "label": "Arguments",
          "defaultValue": "",
          "helpMarkDown": "Arguments passed to the tool",
          "required": false
        },
        {
          "name": "ifCondition",
          "type": "string",
          "label": "If Condition",
          "defaultValue": "",
          "helpMarkDown": "Performs task if this property is set (true, True, 1, -1).",
          "required": false
        },
        {
          "name": "workingFolder",
          "type": "filePath",
          "label": "Working folder",
          "defaultValue": "",
          "required": false,
          "groupName": "advanced"
        },
        {
          "name": "failOnStandardError",
          "type": "boolean",
          "label": "Fail on Standard Error",
          "defaultValue": "false",
          "required": false,
          "helpMarkDown": "If this is true, this task will fail if any errors are written to the StandardError stream.",
          "groupName": "advanced"
        }
      ],
      "instanceNameFormat": "Run $(filename)",
      "execution": {
        "Node": {
          "target": "task.js",
          "argumentFormat": ""
        },
        "PowerShell": {
          "target": "$(currentDirectory)\\task.ps1",
          "argumentFormat": "",
          "workingDirectory": "$(currentDirectory)"
        }
      },
      "messages": {
        "CmdLineReturnCode": "%s exited with return code: %d",
        "CmdLineFailed": "%s failed with error: %s"
      }
    }
    

    task.ps1

    param (
        [string]$filename,
        [string]$arguments,
        [string]$ifCondition,
        [string]$workingFolder,
        [string]$failOnStandardError
    )
    
    
    Write-Host "filename = $filename"
    Write-Host "arguments = $arguments"
    Write-Host "ifCondition = $ifCondition" 
    Write-Host "workingFolder = $workingFolder" 
    Write-Host "failOnStandardError = $failOnStandardError" 
    
    
    #########################################################################
    If ($ifCondition -eq "true" -Or $ifCondition -eq "True" -Or $ifCondition -eq 1 -Or $ifCondition -eq -1)
    {
    
        Write-Host "Creating process"
    
        $pinfo = New-Object System.Diagnostics.ProcessStartInfo
        $pinfo.FileName = $filename
        $pinfo.RedirectStandardError = $true
        $pinfo.RedirectStandardOutput = $true
        $pinfo.UseShellExecute = $false
        $pinfo.Arguments = $arguments
    
    
        $p = New-Object System.Diagnostics.Process
        $p.StartInfo = $pinfo
        $p.StartInfo.WorkingDirectory = $workingFolder
    
        Write-Host "Executing process..."
        $p.Start() | Out-Null
    
        $stdout = $p.StandardOutput.ReadToEnd()
        $stderr = $p.StandardError.ReadToEnd()
    
        $p.WaitForExit(300 * 1000)
        Write-Host "Executing process complete"
    
    
        Write-Host  $stdout
        Write-Host  -Message ("Exit code : {0}" -f $p.ExitCode) -Verbose
    
        if ( $p.ExitCode -eq 1)
        {
            Write-Error -Message ("Stderr : {0}" -f $stderr)
        }
    
    }
    #########################################################################
    

    upload.bat

    tfx build tasks upload --task-path ./ --overwrite
    pause
    

    同样,我认为至少应该包含 jessehouwing 所描述的功能。

    【讨论】:

      猜你喜欢
      • 2018-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多