@@ -2,6 +2,7 @@ import * as fs from "fs";
22import * as path from "path" ;
33import * as tl from 'azure-pipelines-task-lib/task' ;
44import * as os from "os" ;
5+ import { loginAzureRM } from 'azure-pipelines-tasks-artifacts-common/azCliUtils' ;
56import util from "./util" ;
67import Constants from "./constant" ;
78import { TelemetryEvent } from './telemetry' ;
@@ -16,7 +17,7 @@ class azureclitask {
1617 return ! ! tl . which ( "az" , false ) ;
1718 }
1819
19- static async runMain ( deploymentJson , telemetryEvent : TelemetryEvent ) {
20+ static async runMain ( deploymentJson , telemetryEvent : TelemetryEvent ) : Promise < void > {
2021 var toolExecutionError = null ;
2122 try {
2223 let iothub : string = tl . getInput ( "iothubname" , true ) ;
@@ -41,9 +42,9 @@ class azureclitask {
4142 configId = util . normalizeDeploymentId ( configId ) ;
4243 console . log ( tl . loc ( 'NomralizedDeployementId' , configId ) ) ;
4344
44- this . loginAzure ( ) ;
45+ await this . loginAzure ( ) ;
4546
46- tl . debug ( 'OS release:' + os . release ( ) ) ;
47+ tl . debug ( 'OS release:' + os . release ( ) ) ;
4748 let showIotExtensionCommand = [ "extension" , "show" , "--name" , "azure-iot" ] ;
4849 let result = tl . execSync ( 'az' , showIotExtensionCommand , Constants . execSyncSilentOption ) ;
4950 if ( result . code !== 0 ) { // The extension is not installed
@@ -115,9 +116,9 @@ class azureclitask {
115116 let execOptions : IExecOptions = {
116117 errStream : outputStream as stream . Writable
117118 } as IExecOptions ;
118-
119+
119120 // check azcli version
120- let checkAzureIoTVersionExtensionCommand = [ "--version" ] ;
121+ let checkAzureIoTVersionExtensionCommand = [ "--version" ] ;
121122 let viewAzVersionResult = tl . execSync ( 'az' , checkAzureIoTVersionExtensionCommand , execOptions ) ;
122123 if ( viewAzVersionResult . code !== 0 )
123124 {
@@ -131,35 +132,21 @@ class azureclitask {
131132 }
132133 }
133134
134- static loginAzure ( ) {
135+ static async loginAzure ( ) : Promise < void > {
135136 var connectedService = tl . getInput ( "connectedServiceNameARM" , true ) ;
136- this . loginAzureRM ( connectedService ) ;
137- }
138-
139- static loginAzureRM ( connectedService ) {
140- var servicePrincipalId = tl . getEndpointAuthorizationParameter ( connectedService , "serviceprincipalid" , false ) ;
141- var servicePrincipalKey = tl . getEndpointAuthorizationParameter ( connectedService , "serviceprincipalkey" , false ) ;
142- var tenantId = tl . getEndpointAuthorizationParameter ( connectedService , "tenantid" , false ) ;
143- var subscriptionName = tl . getEndpointDataParameter ( connectedService , "SubscriptionName" , true ) ;
144- var environment = tl . getEndpointDataParameter ( connectedService , "environment" , true ) ;
145137 // Work around for build agent az command will exit with non-zero code since configuration files are missing.
146138 tl . debug ( tl . execSync ( "az" , "--version" , Constants . execSyncSilentOption ) . stdout ) ;
147139
140+ var environment = tl . getEndpointDataParameter ( connectedService , "environment" , true ) ;
148141 // Set environment if it is not AzureCloud (global Azure)
149142 if ( environment && environment !== 'AzureCloud' ) {
150143 let result = tl . execSync ( "az" , [ "cloud" , "set" , "--name" , environment ] , Constants . execSyncSilentOption ) ;
151144 tl . debug ( JSON . stringify ( result ) ) ;
152145 }
153146
154- //login using svn
155- let result = tl . execSync ( "az" , [ "login" , "--service-principal" , "-u" , servicePrincipalId , "-p" , servicePrincipalKey , "--tenant" , tenantId ] , Constants . execSyncSilentOption ) ;
156- tl . debug ( JSON . stringify ( result ) ) ;
157- this . throwIfError ( result ) ;
147+ await loginAzureRM ( connectedService ) ;
148+
158149 this . isLoggedIn = true ;
159- //set the subscription imported to the current subscription
160- result = tl . execSync ( "az" , [ "account" , "set" , "--subscription" , subscriptionName ] , Constants . execSyncSilentOption ) ;
161- tl . debug ( JSON . stringify ( result ) ) ;
162- this . throwIfError ( result ) ;
163150 }
164151
165152 static logoutAzure ( ) {
@@ -171,12 +158,6 @@ class azureclitask {
171158 tl . warning ( tl . loc ( "FailedToLogout" ) ) ;
172159 }
173160 }
174-
175- static throwIfError ( resultOfToolExecution ) {
176- if ( resultOfToolExecution . stderr ) {
177- throw resultOfToolExecution ;
178- }
179- }
180161}
181162
182163class imagevalidationtask {
@@ -253,7 +234,7 @@ class imagevalidationtask {
253234 }
254235}
255236
256- export async function run ( telemetryEvent : TelemetryEvent ) {
237+ export async function run ( telemetryEvent : TelemetryEvent ) : Promise < void > {
257238 let inBuildPipeline : boolean = util . checkSelfInBuildPipeline ( ) ;
258239 console . log ( tl . loc ( 'DeployTaskRunningInBuild' , inBuildPipeline ) ) ;
259240 let deploymentFilePath : string = tl . getPathInput ( 'deploymentFilePath' , true ) ;
0 commit comments