【问题标题】:Publishing release notes to TFS/VSTS Wiki during Release在发布期间向 TFS/VSTS Wiki 发布发布说明
【发布时间】:2021-05-12 01:33:56
【问题描述】:

我的任务是在发布触发时自动在 WIKI 上生成和发布发布说明,为此我关注了这个Blog,它非常方便的博客,但我的不幸仍然无法使用发布模板创建 wiki 页面. (同时使用 Azure DevOps 和 TFS)

模板:

**Build Number**  : $($build.buildnumber)    
**Build started** : $("{0:dd/MM/yy HH:mm:ss}" -f [datetime]$build.startTime)     
**Source Branch** : $($build.sourceBranch)  
###Associated work items  
@@WILOOP@@  
* #$($widetail.id)
@@WILOOP@@  
###Associated change sets/commits  
@@CSLOOP@@  
* **ID $($csdetail.changesetid)$($csdetail.commitid)** 
  >$($csdetail.comment)    
@@CSLOOP@@

PowerShell 脚本

$content = [IO.File]::ReadAllText("$(System.DefaultWorkingDirectory)\releasenotes.md")
$data = @{content=$content;} | ConvertTo-Json;
$params = @{uri = '$(WikiPath)';
  Method = 'PUT';
  Headers = @{Authorization = "Bearer $(System.AccessToken)" };
  ContentType = "application/json";
  Body = $data;
}
Invoke-WebRequest @params

请指导我做错了什么

【问题讨论】:

    标签: azure-devops markdown azure-pipelines wiki release-notes


    【解决方案1】:

    在工作级别检查对System.AccessToken 的访问:https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=classic

    此外,请检查您的 wiki 上的权限

    【讨论】:

    • 很好,现在我的日志显示状态代码:200 和状态描述:好的,但仍然没有创建 WIKI 页面 :( 请您分享一下 PS 脚本中使用的 $(WikiPath) 的值吗?
    • @SaadAwan,我没有使用这个扩展,只能提出一些想法))。在 wiki 安全性上检查构建服务的权限。
    【解决方案2】:

    经过测试,我们发现您提到的blog中的PowerShell脚本使用了这个Rest API:Pages - Create Or Update,因此wikipath是请求的url,格式如下:

    https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/{wikiIdentifier}/pages?path={path}&api-version=6.0

    例如,我们创建一个名为 scrum-test.wiki 的项目 wiki,并想创建一个名为 Release notes 的新 wiki 页面,url 如下所示

    https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/scrum-test.wiki/pages?path=Release notes&api-version=6.0

    如果我们现在想在发行说明页面下创建一个名为 0.1.0 的子 wiki 页面,则 url 如下所示

    https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/scrum-test.wiki/pages?path=Release notes/0.1.0&api-version=6.0

    此外,使用 AccessToken 我们总是会收到错误消息,即 "The wiki page operation failed with message : User does not have write permissions for this wiki." 即使我们授予身份的完整 wiki 权限:{project name} Build Service ({organization name}),所以我们使用PAT authentication 具有完全访问权限,并且可以在下面的 PowerShell 脚本中正常工作。

    $content = [IO.File]::ReadAllText("$(System.DefaultWorkingDirectory)\releasenotes.md")
    $data = @{content=$content;} | ConvertTo-Json;
    
    $connectionToken="PAT here"
    
    $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
    
    $params = @{uri = '$(WikiPath)';
      Method = 'PUT';
      Headers = @{Authorization = "Basic $base64AuthInfo" };
      ContentType = "application/json";
      Body = $data;
    }
    Invoke-WebRequest @params
    

    【讨论】:

    • 谢谢大家,$(WikiPath) 是问题所在,更正了链接,现在可以按预期创建 wiki 页面,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多