Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #11456 #11475

Merged
merged 2 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions Tasks/AzureCLIV2/src/Utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import fs = require("fs");

export class Utility {

public static async getScriptPath(scriptLocation:string, fileExtensions:string[]): Promise<string> {
public static async getScriptPath(scriptLocation: string, fileExtensions: string[]): Promise<string> {
if (scriptLocation === "scriptPath") {
let filePath: string = tl.getPathInput("scriptPath", true, true);
if(Utility.checkIfFileExists(filePath, fileExtensions)){
if (Utility.checkIfFileExists(filePath, fileExtensions)) {
return filePath;
}
throw new Error(tl.loc('JS_InvalidFilePath', filePath));
Expand All @@ -33,14 +33,18 @@ export class Utility {
}

let contents: string[] = [];
contents.push(`$ErrorActionPreference = '${powerShellErrorActionPreference}'`);
contents.push(`$ErrorActionPreference = '${powerShellErrorActionPreference}'`);

if (scriptLocation === "scriptPath") {
let filePath: string = tl.getPathInput("scriptPath", true, true);
if (Utility.checkIfFileExists(filePath, fileExtensions)){
contents.push(`. '${filePath.replace("'", "''")}' ${scriptArguments}`.trim());
if (Utility.checkIfFileExists(filePath, fileExtensions)) {
let content: string = `. '${filePath.replace("'", "''")}' `;
if (scriptArguments) {
content += scriptArguments;
}
contents.push(content.trim());
}
else{
else {
throw new Error(tl.loc('JS_InvalidFilePath', filePath));
}
}
Expand All @@ -64,7 +68,7 @@ export class Utility {
tl.checkPath(tempDirectory, `${tempDirectory} (agent.tempDirectory)`);
let scriptPath: string = path.join(tempDirectory, `azureclitaskscript${new Date().getTime()}.${fileExtensions[0]}`);

await Utility.createFile(scriptPath,'\ufeff' + contents.join(os.EOL), { encoding : 'utf8'} );
await Utility.createFile(scriptPath, '\ufeff' + contents.join(os.EOL), { encoding: 'utf8' });
return scriptPath;
}

Expand All @@ -82,7 +86,7 @@ export class Utility {
}
}

public static async createFile(filePath: string, data: string, options?:any): Promise<void> {
public static async createFile(filePath: string, data: string, options?: any): Promise<void> {
try {
fs.writeFileSync(filePath, data, options);
}
Expand All @@ -93,12 +97,12 @@ export class Utility {
}

public static checkIfFileExists(filePath: string, fileExtensions: string[]): boolean {
let matchingFiles:string[] = fileExtensions.filter((fileExtension:string) => {
let matchingFiles: string[] = fileExtensions.filter((fileExtension: string) => {
if (tl.stats(filePath).isFile() && filePath.toUpperCase().match(new RegExp(`\.${fileExtension.toUpperCase()}$`))) {
return true;
}
});
if (matchingFiles.length > 0){
if (matchingFiles.length > 0) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 1
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 1
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down