1
votes

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

Release 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,

1
Since you don't link build artifact to release, which data that you want to retrieve?starian chen-MSFT
Hi @starain-MSFT , Thanks a lot for the reply. We are adding our extension as a Task to run during execution in one of environment in release. And this task will attach file while executing release. We need to retrieve data in this file once it completes the executionLalindu
Do you try it with getPlanAttachements() method? visualstudio.com/en-us/docs/integrate/extensions/reference/…starian chen-MSFT
Hi @ starain-MSFT I couldn't find any way to get planId of release planId = releaseData.environments[0].deploySteps[0].runPlanId; gives me guid which seems like incorrect . I get error when I use above plan Id in taskClient.getPlanAttachments(vsoContext.project.id, "release", planid , "abc")Lalindu
@Lalindu How do you attach the file during the execution? Call "##vso[task.uploadfile]local file path" command?Eddie Chen - MSFT

1 Answers

0
votes

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();
            });

        }