@@ -12,6 +12,9 @@ function convertToNullIfUndefined<T>(arg: T): T|null {
12
12
}
13
13
14
14
async function run ( ) {
15
+ let input_workingDirectory = tl . getPathInput ( 'workingDirectory' , /*required*/ true , /*check*/ true ) ;
16
+ let tempDirectory = tl . getVariable ( 'agent.tempDirectory' ) ;
17
+ tl . checkPath ( tempDirectory , `${ tempDirectory } (agent.tempDirectory)` ) ;
15
18
try {
16
19
tl . setResourcePath ( path . join ( __dirname , 'task.json' ) ) ;
17
20
@@ -35,7 +38,6 @@ async function run() {
35
38
let customTargetAzurePs : string = convertToNullIfUndefined ( tl . getInput ( 'CustomTargetAzurePs' , false ) ) ;
36
39
let serviceName = tl . getInput ( 'ConnectedServiceNameARM' , /*required*/ true ) ;
37
40
let endpointObject = await new AzureRMEndpoint ( serviceName ) . getEndpoint ( ) ;
38
- let input_workingDirectory = tl . getPathInput ( 'workingDirectory' , /*required*/ true , /*check*/ true ) ;
39
41
let isDebugEnabled = ( process . env [ 'SYSTEM_DEBUG' ] || "" ) . toLowerCase ( ) === "true" ;
40
42
41
43
// string constants
@@ -99,8 +101,6 @@ async function run() {
99
101
100
102
// Write the script to disk.
101
103
tl . assertAgent ( '2.115.0' ) ;
102
- let tempDirectory = tl . getVariable ( 'agent.tempDirectory' ) ;
103
- tl . checkPath ( tempDirectory , `${ tempDirectory } (agent.tempDirectory)` ) ;
104
104
let filePath = path . join ( tempDirectory , uuidV4 ( ) + '.ps1' ) ;
105
105
106
106
await fs . writeFile (
@@ -160,6 +160,30 @@ async function run() {
160
160
catch ( err ) {
161
161
tl . setResult ( tl . TaskResult . Failed , err . message || 'run() failed' ) ;
162
162
}
163
+ finally {
164
+ try {
165
+ const powershell = tl . tool ( tl . which ( 'pwsh' ) || tl . which ( 'powershell' ) || tl . which ( 'pwsh' , true ) )
166
+ . arg ( '-NoLogo' )
167
+ . arg ( '-NoProfile' )
168
+ . arg ( '-NonInteractive' )
169
+ . arg ( '-ExecutionPolicy' )
170
+ . arg ( 'Unrestricted' )
171
+ . arg ( '-Command' )
172
+ . arg ( `. '{path.join(path.resolve(__dirname),'RemoveAzContext.ps1')}'` ) ;
173
+
174
+ let options = < tr . IExecOptions > {
175
+ cwd : input_workingDirectory ,
176
+ failOnStdErr : false ,
177
+ errStream : process . stdout , // Direct all output to STDOUT, otherwise the output may appear out
178
+ outStream : process . stdout , // of order since Node buffers it's own STDOUT but not STDERR.
179
+ ignoreReturnCode : true
180
+ } ;
181
+ await powershell . exec ( options ) ;
182
+ }
183
+ catch ( err ) {
184
+ tl . debug ( "Az-clearContext not completed due to an error" ) ;
185
+ }
186
+ }
163
187
}
164
188
165
189
run ( ) ;
0 commit comments