@@ -14,9 +14,9 @@ export class Utility {
1414 }
1515 throw new Error ( tl . loc ( 'JS_InvalidFilePath' , filePath ) ) ;
1616 }
17- let tmpDir = tl . getVariable ( 'Agent.TempDirectory' ) || os . tmpdir ( ) ;
17+ let tempDirectory = tl . getVariable ( 'Agent.TempDirectory' ) || os . tmpdir ( ) ;
1818 let inlineScript : string = tl . getInput ( "inlineScript" , true ) ;
19- let scriptPath : string = path . join ( tmpDir , `azureclitaskscript${ new Date ( ) . getTime ( ) } .${ fileExtensions [ 0 ] } ` ) ;
19+ let scriptPath : string = path . join ( tempDirectory , `azureclitaskscript${ new Date ( ) . getTime ( ) } .${ fileExtensions [ 0 ] } ` ) ;
2020 await Utility . createFile ( scriptPath , inlineScript ) ;
2121 return scriptPath ;
2222 }
@@ -32,26 +32,30 @@ export class Utility {
3232 throw new Error ( tl . loc ( 'JS_InvalidErrorActionPreference' , powerShellErrorActionPreference ) ) ;
3333 }
3434
35+ // Write the script to disk.
36+ tl . assertAgent ( '2.115.0' ) ;
37+ let tempDirectory = tl . getVariable ( 'Agent.TempDirectory' ) || os . tmpdir ( ) ;
38+
3539 let contents : string [ ] = [ ] ;
3640 contents . push ( `$ErrorActionPreference = '${ powerShellErrorActionPreference } '` ) ;
37-
38- if ( scriptLocation === "scriptPath" ) {
39- let filePath : string = tl . getPathInput ( "scriptPath" , true , true ) ;
40- if ( Utility . checkIfFileExists ( filePath , fileExtensions ) ) {
41- let content : string = `. '${ filePath . replace ( "'" , "''" ) } ' ` ;
42- if ( scriptArguments ) {
43- content += scriptArguments ;
44- }
45- contents . push ( content . trim ( ) ) ;
46- }
47- else {
41+ let filePath : string = tl . getPathInput ( "scriptPath" , false , true ) ; ;
42+ if ( scriptLocation === "inlineScript" ) {
43+ let inlineScript : string = tl . getInput ( "inlineScript" , true ) ;
44+ filePath = path . join ( tempDirectory , `azureclitaskscript${ new Date ( ) . getTime ( ) } _inlinescript.${ fileExtensions [ 0 ] } ` ) ;
45+ await Utility . createFile ( filePath , inlineScript ) ;
46+ }
47+ else {
48+ if ( ! Utility . checkIfFileExists ( filePath , fileExtensions ) ) {
4849 throw new Error ( tl . loc ( 'JS_InvalidFilePath' , filePath ) ) ;
4950 }
5051 }
51- else {
52- let inlineScript : string = tl . getInput ( "inlineScript" , true ) ;
53- contents . push ( inlineScript ) ;
52+
53+ let content : string = `. '${ filePath . replace ( "'" , "''" ) } ' ` ;
54+ if ( scriptArguments ) {
55+ content += scriptArguments ;
5456 }
57+ contents . push ( content . trim ( ) ) ;
58+
5559 let powerShellIgnoreLASTEXITCODE : string = tl . getInput ( 'powerShellIgnoreLASTEXITCODE' , false ) ;
5660 if ( ! powerShellIgnoreLASTEXITCODE ) {
5761 contents . push ( `if (!(Test-Path -LiteralPath variable:\LASTEXITCODE)) {` ) ;
@@ -62,12 +66,7 @@ export class Utility {
6266 contents . push ( `}` ) ;
6367 }
6468
65- // Write the script to disk.
66- tl . assertAgent ( '2.115.0' ) ;
67- let tempDirectory = tl . getVariable ( 'agent.tempDirectory' ) ;
68- tl . checkPath ( tempDirectory , `${ tempDirectory } (agent.tempDirectory)` ) ;
6969 let scriptPath : string = path . join ( tempDirectory , `azureclitaskscript${ new Date ( ) . getTime ( ) } .${ fileExtensions [ 0 ] } ` ) ;
70-
7170 await Utility . createFile ( scriptPath , '\ufeff' + contents . join ( os . EOL ) , { encoding : 'utf8' } ) ;
7271 return scriptPath ;
7372 }
0 commit comments