您可以通过数据库访问 TFS 2017 构建定义吗?

Can you access TFS 2017 build definition through the database?

我曾一度创建了一些 TFS 2017 构建定义,但由于对安装和数据库进行了一些乱七八糟的操作,我无法访问这些定义。它们不会出现在门户网站的任何地方。我也无法恢复和附加与它们关联的项目集合,尽管我确实有项目集合数据库的实际 SQL 备份。

那么,有没有办法查询 Tfs_Configuration、Tfs_Warehouse 或 Tfs_projectcollection 数据库来检索构建定义信息?

如果没有,我最终会重新创建它们,但很好奇是否还有其他方法。

如果定义简单,建议重新创建,不会花太多时间。

但如果它们很复杂,你可以在另一个sql实例中恢复备份数据库,查询出丢失的构建定义,然后将定义插入当前table [Tfs_DefaultCollection].[构建].[tbl_Definition]。 (确保在执行此操作之前备份数据库,以防遇到任何问题。)

只需 select 一行并从查询的定义中复制(右键单击 > copy in sql server),您需要执行其他操作以为每个值添加“ ”。

然后像这样插入值:

insert into [Tfs_DefaultCollection].[Build].[tbl_Definition] 
values 
('1',   '85',   '17',   '1',    'D4',   '1',    '7',    '0',    '5',    '8',    '1',    '', '$(date:yyyyMMdd)$(rev:.r)',    '1',    '60',   '', '1F739003-44A9-4AB6-B1A2-D3CD2A291588', '2017-04-21 19:53:49.733',  '', '[{"enabled":false,"definition":{"id":"7c555368-ca64-4199-add6-9ebaf0b0137d"},"inputs":{"multipliers":"[]","parallel":"false","continueOnError":"true","additionalFields":"{}"}},{"enabled":false,"definition":{"id":"a9db38f9-9fdc-478c-b0f9-464221e58316"},"inputs":{"workItemType":"106","assignToRequestor":"true","additionalFields":"{}"}},{"enabled":false,"definition":{"id":"57578776-4c22-4526-aeb0-86b6da17ee9c"},"inputs":{"additionalFields":"{}"}}]', '{"properties":{"labelSources":"0","tfvcMapping":"{\"mappings\":[{\"serverPath\":\"$/6553c041-5e50-4ace-bec2-c1dba2b812ca\",\"mappingType\":\"map\",\"localPath\":\"\\\"},{\"serverPath\":\"$/6553c041-5e50-4ace-bec2-c1dba2b812ca/Drops\",\"mappingType\":\"cloak\",\"localPath\":\"\\\"}]}","cleanOptions":"0"},"id":"$/","type":"TfsVersionControl","name":"6553c041-5e50-4ace-bec2-c1dba2b812ca","url":"http://win-kev0061habi:8080/tfs/DefaultCollection/","defaultBranch":"$/6553c041-5e50-4ace-bec2-c1dba2b812ca","rootFolder":"$/6553c041-5e50-4ace-bec2-c1dba2b812ca","clean":"false","checkoutSubmodules":false}',    '', '[{"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"NuGet restore **\*.sln","timeoutInMinutes":0,"task":{"id":"333b11bd-d341-40d9-afcf-b32d5ce6f23b","versionSpec":"0.*","definitionType":"task"},"inputs":{"solution":"**\*.sln","nugetConfigPath":"","restoreMode":"restore","noCache":"false","nuGetRestoreArgs":"","verbosity":"-","nuGetVersion":"3.3.0","nuGetPath":""}},{"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"Build solution **\*.sln","timeoutInMinutes":0,"task":{"id":"71a9a2d3-a98a-4caa-96ab-affca411ecda","versionSpec":"1.*","definitionType":"task"},"inputs":{"solution":"**\*.sln","msbuildArgs":"","platform":"$(BuildPlatform)","configuration":"$(BuildConfiguration)","clean":"false","vsVersion":"15.0","maximumCpuCount":"false","restoreNugetPackages":"false","msbuildArchitecture":"x86","logProjectEvents":"true","createLogFile":"false"}},{"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"Test Assemblies **\$(BuildConfiguration)\*test*.dll;-:**\obj\**","timeoutInMinutes":0,"task":{"id":"ef087383-ee5e-42c7-9a53-ab56c98420f9","versionSpec":"1.*","definitionType":"task"},"inputs":{"testAssembly":"**\$(BuildConfiguration)\*test*.dll;-:**\obj\**","testFiltercriteria":"","runSettingsFile":"","overrideTestrunParameters":"","codeCoverageEnabled":"false","runInParallel":"false","vstestLocationMethod":"version","vsTestVersion":"14.0","vstestLocation":"","pathtoCustomTestAdapters":"","otherConsoleOptions":"","testRunTitle":"","platform":"$(BuildPlatform)","configuration":"$(BuildConfiguration)","publishRunAttachments":"true"}},{"enabled":true,"continueOnError":true,"alwaysRun":false,"displayName":"Publish symbols path: ","timeoutInMinutes":0,"task":{"id":"0675668a-7bba-4ccb-901d-5ad6554ca653","versionSpec":"1.*","definitionType":"task"},"inputs":{"SymbolsPath":"","SearchPattern":"**\bin\**\*.pdb","SymbolsFolder":"","SkipIndexing":"false","TreatNotIndexedAsWarning":"false","SymbolsMaximumWaitTime":"","SymbolsProduct":"","SymbolsVersion":"","SymbolsArtifactName":"Symbols_$(BuildConfiguration)"}},{"enabled":true,"continueOnError":false,"alwaysRun":true,"displayName":"Copy Files to: $(build.artifactstagingdirectory)","timeoutInMinutes":0,"task":{"id":"5bfb729a-a7c8-4a78-a7c3-8d717bb7c13c","versionSpec":"2.*","definitionType":"task"},"inputs":{"SourceFolder":"$(build.sourcesdirectory)","Contents":"**\bin\$(BuildConfiguration)\**","TargetFolder":"$(build.artifactstagingdirectory)","CleanTargetFolder":"false","OverWrite":"false","flattenFolders":"false"}},{"enabled":true,"continueOnError":false,"alwaysRun":true,"displayName":"Publish Artifact: drop","timeoutInMinutes":0,"task":{"id":"2ff763a7-ce83-4e1f-bc89-0ae63477cebe","versionSpec":"1.*","definitionType":"task"},"inputs":{"PathtoPublish":"$(build.artifactstagingdirectory)","ArtifactName":"drop","ArtifactType":"Container","TargetPath":"\\my\share\$(Build.DefinitionName)\$(Build.BuildNumber)"}}]',   '{"system.debug":{"value":"false","allowOverride":true},"BuildConfiguration":{"value":"release","allowOverride":true},"BuildPlatform":{"value":"any cpu","allowOverride":true}}',   '', '[{"branches":["+refs/heads/*"],"artifacts":[],"artifactTypesToDelete":["FilePath","SymbolStore"],"daysToKeep":10,"minimumToKeep":1,"deleteBuildRecord":true,"deleteTestResults":true}]',   '0',    '0',    '1',    '')

如果你有很多定义需要做,你也可以尝试合并数据库,详情请参考下面link: http://byalexblog.net/merge-sql-databases