我最近加入了一家没有 Azure Dev Ops wiki 的公司,但他们确实拥有大量记录在案的流程,并将其保存在共享点库中。我已经与公司的其他成员交谈过,他们多年来一直试图说服管理层允许使用 DevOps wiki,但无济于事。
不知道我是怎么做到的,但现在我们有权开始使用它来保存使用开发操作、创建管道、管理工作项目等的“操作方法”,但条件是有关 wiki 的信息可以保留在共享点在某处作为目录列出。
管理层想要的是:
(维基页面的)名称 网址 最后更新
每次更新 wiki 时,都会更新目录。
这样可以从目录访问 wiki 页面以及当前的共享点文档库。
我看过,有很多关于如何克隆 wiki 或从中创建 PDF 或 Word 文档的解决方案,但不是 wiki 的数据,而是内容本身。
Powerautomate 似乎与 wiki 没有任何连接或触发器,所以我陷入了困境。
这可能吗?
没有内置功能可将 Azure DevOps wiki 中的文件同步到 SharePoint 站点文件夹中。但是,根据您的要求,您可以使用下面的示例管道进行测试。
Set up Build
(以启用 CI
触发器);trigger:
branches:
include:
- wikiMaster
paths:
include:
- /**/*.md
pool:
vmImage: windows-latest
steps:
- checkout: self
fetchDepth: 0
- powershell: |
tree $(System.DefaultWorkingDirectory) /F /A
Write-Host "================1. Get the updated file path of the triggering commit ================"
$headers = @{
Authorization = "bearer $(System.AccessToken)"
}
$commitChangeURL = "$(System.CollectionUri)/TheProjectName/_apis/git/repositories/TheProjectName.wiki/commits/$(Build.SourceVersion)/changes?api-version=7.2-preview.1"
Write-Host "commitChangeURL is $commitChangeURL"
$commitChangeResponse = Invoke-RestMethod -Uri $commitChangeURL -Method GET -Headers $headers -ContentType 'application/json' -Verbose
Write-Host "================2. Get the page URL ================"
foreach ($change in $commitChangeResponse.changes) {
If ($change.item.gitObjectType -eq "blob"){
$path = $change.item.path
Write-Host "Updated .md file Path is $path"
$wikiPageName = ($path -split '\.')[0]
Write-Host "wikiPageName is $wikiPageName"
$getWikiPageURL = "$(System.CollectionUri)/TheProjectName/_apis/wiki/wikis/TheProjectName.wiki/pages?path=$wikiPageName&api-version=7.2-preview.1"
$getWikiPageResponse = Invoke-RestMethod -Uri $getWikiPageURL -Method GET -Headers $headers -ContentType 'application/json' -Verbose # | ConvertFrom-Json
$wikiPageId = $getWikiPageResponse.id
Write-Host "The wiki page URL is $(System.CollectionUri)/TheProjectName/_wiki/wikis/TheProjectName.wiki/$wikiPageId"
}
}
displayName: Get updated wiki page URL
- task: az-pipelines-2-sharepoint@0
displayName: Upload the files from System.DefaultWorkingDirectory to SharePoint site
inputs:
tenantId: '$(TenantId)'
clientId: '$(ClientId)'
clientSecret: '$(ClientSecret)'
driveId: 'https://$(SharePointOnline).sharepoint.com/sites/AzureDevOpsTeamSite/Shared%20Documents/'
targetFolder: 'AzureDevOpsProjectWiki'
sourceFolder: '$(System.DefaultWorkingDirectory)'
contents: '**'
conflictBehaviour: 'replace'
cleanTargetFolder: true
flattenFolders: false
failOnEmptySource: false
- task: az-pipelines-2-sharepoint@0
displayName: Upload the files from System.DefaultWorkingDirectory/.attachments to SharePoint site
inputs:
tenantId: '$(TenantId)'
clientId: '$(ClientId)'
clientSecret: '$(ClientSecret)'
driveId: 'https://$(SharePointOnline).sharepoint.com/sites/AzureDevOpsTeamSite/Shared%20Documents/'
targetFolder: 'AzureDevOpsProjectWiki/.attachments'
sourceFolder: '$(System.DefaultWorkingDirectory)/.attachments'
contents: '**'
conflictBehaviour: 'replace'
cleanTargetFolder: true
flattenFolders: false
failOnEmptySource: false
我们需要知道更新后的wiki页面URL;为此,我们可以调用 powershell
管道任务中的 API Commits - Get Changes 和
Pages - Get Page来根据触发提交了解更新后的 wiki 页面 URL
$(Build.SourceVersion)
;
我们可以使用3rd-party扩展上传文件到SharePoint Online - Visual Studio Marketplace先清除SharePoint目标文件夹,然后将管道代理上工作目录中的所有文件上传到SharePoint目标文件夹中;请参阅 参考资料,了解有关该任务如何根据 Azure AD 中的应用程序注册验证对共享点的访问的更多详细信息。
该任务似乎忽略了所有名称以
.
开头的文件和文件夹;为此,我添加了另一个任务来从 wiki 存储库的 .attachments
目录上传文件;
由于工作流程将首先从 SharePoint 目标文件夹中删除所有内容,因此在将工作流程与您的生产内容集成之前,请使用 SharePoint 目录进行测试,以避免意外删除数据