是否可以在TFS2015構建vNext中集中控制構建流程?假設我希望在構建之前和之後執行一些業務任務(自定義任務),但不希望用戶能夠在構建定義編輯器中刪除或更改這些任務的位置。在Team Build 2015中控制構建任務流程
還是有沒有辦法創建一個構建定義模板來實現相同的通過不公開任務?
注:我不想使用XAML構建的定義,因爲它不具有新xPlat建設能力等
是否可以在TFS2015構建vNext中集中控制構建流程?假設我希望在構建之前和之後執行一些業務任務(自定義任務),但不希望用戶能夠在構建定義編輯器中刪除或更改這些任務的位置。在Team Build 2015中控制構建任務流程
還是有沒有辦法創建一個構建定義模板來實現相同的通過不公開任務?
注:我不想使用XAML構建的定義,因爲它不具有新xPlat建設能力等
不,這是不可能的。如果他們是自定義任務,他們可以設置和檢查一個變量,以確保它們按正確的順序運行,但這是你必須實現的東西。
構建框架或代理基礎結構中目前沒有任何內容強制或部分指定只能在特定位置進行擴展的構建模板。
也不可能在工作流程的早期步驟中註冊類似「終結器」的東西。
至少應該包含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源,並修改它包括如果條件財產。我創建了一個默認值爲false的生成變量,並將其關閉。允許在隊列時間,然後將該變量放置在如果條件屬性的任務。我修改了的powershell腳本:
If ($ifCondition -eq "true" -Or $ifCondition -eq "True" -Or $ifCondition -eq 1 -Or $ifCondition -eq -1)
{
Write-Host "Creating process"
...
}
當我排隊的生成,如果我改變變量設置爲1,-1,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描述的特徵。
我想知道你在談論什麼樣的前/後步驟。這聽起來像是不是真的意味着在構建... – jessehouwing
作爲審計要求的一部分,我想存檔的來源和運行一些依賴關係的報告,這些是我的業務授權,我不希望用戶跳過這個。 – Anbu
由於構建鏈接到特定的簽入/提交,構建完成後生成這些額外的東西是不是更容易? – jessehouwing