简体   繁体   English

Azure DevOps 扩展:将查询参数传递给自定义生成报告视图

[英]Azure DevOps Extension: Passing query parameters to custom build report view

I am building a custom extension for Azure DevOps, specifically a build tab extension .我正在为 Azure DevOps 构建自定义扩展,特别是构建选项卡扩展 I have a rather basic definition in my manifest.json file.我的 manifest.json 文件中有一个相当基本的定义。

{
  "id": "my-report-hub",
  "type": "ms.vss-build-web.build-results-tab",
  "targets": [
    "ms.vss-build-web.build-results-view"
  ],
  "properties": {
    "name": "My Build Report",
    "uri": "build/myReport.html"
  }
}

The HTML for the report is dynamic, and there are generated variables that help define the page contents.报告的 HTML 是动态的,并且生成了有助于定义页面内容的变量。 Essentially the report page shows a list of build errors, and if you click on the error I dynamically bring up a more detailed description of the error.本质上,报告页面显示了构建错误列表,如果您单击错误,我会动态显示错误的更详细描述。

What I am trying to do is deep link one of these generated pages, which means calling the URL for my build view but somehow passing it parameters.我想要做的是深层链接这些生成的页面之一,这意味着调用我的构建视图的 URL,但以某种方式传递它的参数。 The URL generally looks like this: URL 通常如下所示:

https://dev.azure.com/{org}/{project}/_build/results?buildId=302&view=thrillo.my-extension-debug.my-report-hub

But of course this brings up the main page.但当然这会带来主页。 I want to pass parameters that my TypeScript/JavaScript can read and subsequently pop up the generated page associated with the error number.我想传递我的 TypeScript/JavaScript 可以读取的参数,然后弹出与错误号关联的生成页面。 For example I could add a parameter like this:例如,我可以添加这样的参数:

https://dev.azure.com/{org}/{project}/_build/results?buildId=302&view=thrillo.my-extension-debug.my-report-hub&errno=11

But when my actual asset's HTML/JS is called it is within an iframe and does not get the arguments (in fact it gets a link to the asset page itself with no query parameters, more or less).但是当我的实际资产的 HTML/JS 被调用时,它在一个 iframe 中并且没有得到参数(实际上它得到了一个指向资产页面本身的链接,没有查询参数,或多或少)。 I cannot get the "top document" in order to get the view parameters, of course, because that jumps across domains and I have no access (security!)我无法获得“顶级文档”以获取视图参数,当然,因为它跨域跳转而我无权访问(安全!)

So the question is: how can I pass an argument through a link/url to my build report view, if that is indeed possible?所以问题是:如果确实可能,我如何通过链接/url 将参数传递给我的构建报告视图?

Thanks for the help!谢谢您的帮助!

I had the same requirement.我有同样的要求。 It's a bit confusing as parts of the documentation point to the new SDK, some to the old;这有点令人困惑,因为文档的一部分指向新的 SDK,一些指向旧的; however, using this: https://docs.microsoft.com/en-us/javascript/api/azure-devops-extension-api/ihostnavigationservice I was able to get to:然而,使用这个: https : //docs.microsoft.com/en-us/javascript/api/azure-devops-extension-api/ihostnavigationservice我能够:

    import * as SDK from "azure-devops-extension-sdk";
    import { CommonServiceIds, IHostNavigationService} from "azure-devops-extension-api";

    public componentDidMount() {
        SDK.init();
        const hostNavigationService = await SDK.getService<IHostNavigationService>(CommonServiceIds.HostNavigationService);
        let pageNavigationParams = await hostNavigationService.getQueryParams();
        console.log(pageNavigationParams)
    }

Then, adding &errno=11 to the URL should show up in pageNavigationParams .然后,将&errno=11添加到 URL 应显示在pageNavigationParams

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM