1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 # Copyright (C) Marc Hoersken, <info@marc-hoersken.de>
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at https://curl.se/docs/copyright.html.
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 # SPDX-License-Identifier: curl
24 ###########################################################################
32 use base qw(Exporter);
35 azure_check_environment
37 azure_create_test_result
38 azure_update_test_result
43 use POSIX qw(strftime);
45 sub azure_check_environment {
46 if(defined $ENV{'AZURE_ACCESS_TOKEN'} && $ENV{'AZURE_ACCESS_TOKEN'} &&
47 defined $ENV{'AGENT_JOBNAME'} && $ENV{'BUILD_BUILDID'} &&
48 defined $ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'} &&
49 defined $ENV{'SYSTEM_TEAMPROJECTID'}) {
55 sub azure_create_test_run {
57 my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
58 my $azure_run=`$curl --silent --noproxy "*" \\
59 --header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
60 --header "Content-Type: application/json" \\
63 'name': '$ENV{'AGENT_JOBNAME'}',
65 'build': {'id': '$ENV{'BUILD_BUILDID'}'}
68 "$azure_baseurl/_apis/test/runs?api-version=5.1"`;
69 if($azure_run =~ /"id":(\d+)/) {
75 sub azure_create_test_result {
76 my ($curl, $azure_run_id, $testnum, $testname)=@_;
77 $testname =~ s/\\/\\\\/g;
78 $testname =~ s/\"/\\\"/g;
79 $testname =~ s/\'/'"'"'/g;
80 my $title_testnum=sprintf("%04d", $testnum);
81 my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
82 my $azure_result=`$curl --silent --noproxy '*' \\
83 --header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
84 --header 'Content-Type: application/json' \\
88 "build": {"id": "$ENV{'BUILD_BUILDID'}"},
89 "testCase": {"id": $testnum},
90 "testCaseTitle": "$title_testnum: $testname",
91 "testCaseRevision": 2,
92 "automatedTestName": "curl.tests.$testnum",
93 "outcome": "InProgress"
97 '$azure_baseurl/_apis/test/runs/$azure_run_id/results?api-version=5.1'`;
98 if($azure_result =~ /\[\{"id":(\d+)/) {
104 sub azure_update_test_result {
105 my ($curl, $azure_run_id, $azure_result_id, $testnum, $error, $start, $stop)=@_;
109 my $azure_start = strftime "%Y-%m-%dT%H:%M:%SZ", gmtime $start;
110 my $azure_complete = strftime "%Y-%m-%dT%H:%M:%SZ", gmtime $stop;
111 my $azure_duration = sprintf("%.0f", ($stop-$start)*1000);
114 $azure_outcome = 'NotApplicable';
117 $azure_outcome = 'NotExecuted';
120 $azure_outcome = 'Passed';
123 $azure_outcome = 'Failed';
125 my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
126 my $azure_result=`$curl --silent --noproxy '*' --request PATCH \\
127 --header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
128 --header "Content-Type: application/json" \\
132 "id": $azure_result_id,
133 "outcome": "$azure_outcome",
134 "startedDate": "$azure_start",
135 "completedDate": "$azure_complete",
136 "durationInMs": $azure_duration
140 '$azure_baseurl/_apis/test/runs/$azure_run_id/results?api-version=5.1'`;
141 if($azure_result =~ /\[\{"id":(\d+)/) {
147 sub azure_update_test_run {
148 my ($curl, $azure_run_id)=@_;
149 my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
150 my $azure_run=`$curl --silent --noproxy '*' --request PATCH \\
151 --header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
152 --header 'Content-Type: application/json' \\
158 '$azure_baseurl/_apis/test/runs/$azure_run_id?api-version=5.1'`;
159 if($azure_run =~ /"id":(\d+)/) {