Populate data in to VSTS release summary tab

家住魔仙堡 提交于 2019-12-01 09:53:23

问题


I am trying to create a release without mapping a existing build in TFS/VSTS and get data display in release summary once it is completed. in plain text steps are following

  • Release -> Empty Release Definition -> Add build task - > Create Release -> Deploy -> View Data in Summary Section

Summary data are view-able as expected without any issues with following two scenarios

  1. Build - > Create build definition -> Add task - > Save and Queue build – Build Success - > View Summary Data
  2. Release -> Empty Release Definition -> Link pre-defined Build definition -> Create Release -> provide successfully ran build version -> View Summary data.

As As per our understanding the issue occurs when we retrieving artifacts of the given release. We can retrieve results for builds but fail to do the same for releases. Below is the sample code we use to read release data. It will be much helpful if you can provide us guidance on retrieving artifacts details for given release. Right now we use following code in the client side for retrieving release artifacts but it complains release.artifacts is undefined. We have verified that the attachment file is saved to the given file location.

var c = VSS.getConfiguration();
c.onReleaseChanged(function (release) {
         release.artifacts.forEach(function (art) {
                var buildid = art.definitionReference.version.id;
// rest of the code is removed here

         });
});

below are the references we followed to find solution,

  • https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md

  • How to retrieve build attachment from VSTS release summary tab

  • https://github.com/Microsoft/vsts-extension-samples/blob/master/release-management/deployment-status-enhancer/scripts/main.js

  • https://github.com/Microsoft/vsts-extension-samples/blob/master/release-management/deployment-status-enhancer/index.html

  • https://www.visualstudio.com/en-us/docs/integrate/extensions/reference/client/core-sdk#method_getConfiguration


回答1:


I was able to figure out an answer for this issue. I am herewith sharing same for others reference.

If we don’t link an artifact(build definition), then the artifacts for the release/release definition will not be filled with the data, so we won’t be able to refer to the attachment that got uploaded as part of the build.

Hence as per current API implementation, Below are the steps to follow to achieve this requirenment.

  • Writing data in to log while extension run as build task
  • Read above data once build completes (in client side)
  • Display retrieved (processed if required) data in release tab.

I found below code which explains retrieving data from log (reference : https://github.com/Dynatrace/Dynatrace-AppMon-TFS-Integration-Plugin/blob/master/src/enhancer/dynatrace-testautomation.ts)

public initialize(): void {
        super.initialize();
        // Get configuration that's shared between extension and the extension host
        var sharedConfig: TFS_Release_Extension_Contracts.IReleaseViewExtensionConfig = VSS.getConfiguration();
        if(sharedConfig) {
            // register your extension with host through callback
            sharedConfig.onReleaseChanged((release: TFS_Release_Contracts.Release) => {
                // get the dynatraceTestRun attachment from the build
                var rmClient = RM_Client.getClient();
                var LOOKFOR_TASK = "Collect Dynatrace Testrun Results";
                var LOOKFOR_TESTRUNDATA = "\"testRunData\":";

                var drcScope = this;

                release.environments.forEach(function (env) {
                    var _env = env;
                    //project: string, releaseId: number, environmentId: number, taskId: number
                    rmClient.getTasks(VSS.getWebContext().project.id, release.id, env.id).then(function(tasks){
                        tasks.forEach(function(task){
                            if (task.name == LOOKFOR_TASK){
                                rmClient.getLog(VSS.getWebContext().project.id, release.id, env.id, task.id).then(function(log){
                                    var iTRD = log.indexOf(LOOKFOR_TESTRUNDATA);
                                    if (iTRD > 0){
                                        var testRunData = JSON.parse(log.substring(iTRD + LOOKFOR_TESTRUNDATA.length, log.indexOf('}',iTRD)+1));

                                        drcScope.displayDynatraceTestRunData.bind(drcScope);
                                        drcScope.displayDynatraceTestRunData(_env.name, testRunData);
                                    }
                                });
                            }
                        });
                    });
                });
            });

            sharedConfig.onViewDisplayed(() => {
                VSS.resize();
            });

        }


来源:https://stackoverflow.com/questions/44451462/populate-data-in-to-vsts-release-summary-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!