Skip to content

Commit

Permalink
Node6hotfixes/azure power shell (#14172)
Browse files Browse the repository at this point in the history
* Set up CI with Azure Pipelines

[skip ci]

* adding the exact copy of the webdeployment-common-v2 in common-npm-packages

* adding changes for making exposing it as npm package

* Revert "Set up CI with Azure Pipelines"

This reverts commit 409f46b.

* Revert "adding changes for making exposing it as npm package"

This reverts commit 7056479.

* Revert "adding the exact copy of the webdeployment-common-v2 in common-npm-packages"

This reverts commit 631fa44.

* [AzurePowerShellV4] adding node 10 update changes

* Updating the package.json with node 10 dependency
* Updating the minor version and node execution to node 10
* Changing the path for utility-common
* Changing the code which was incompatible with new version of typescript and node10(fs.writeFile)
* Changing the code to incorporate change in behavior for azure-lib

* [AzurePowerShellV5] adding changes for node 10 update

* Updating the package.json with node 10 dependency
* Updating the minor version and node execution to node 10
* Changing the path for utility-common
* Changing the code which was incompatible with new version of typescript and node10(fs.writeFile)
* Changing the code to incorporate change in behavior for azure-lib

* [AzurePowerShellV5] adding changes to make code more type safe and implementing othe review changes
  • Loading branch information
agrataru authored Mar 1, 2021
1 parent d708000 commit c28f82e
Show file tree
Hide file tree
Showing 12 changed files with 951 additions and 122 deletions.
32 changes: 18 additions & 14 deletions Tasks/AzurePowerShellV4/azurepowershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import path = require('path');
import os = require('os');
import tl = require('azure-pipelines-task-lib/task');
import tr = require('azure-pipelines-task-lib/toolrunner');
import * as telemetry from 'utility-common-v2/telemetry';
import * as telemetry from 'azure-pipelines-tasks-utility-common/telemetry';
import { AzureRMEndpoint } from 'azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-endpoint';
var uuidV4 = require('uuid/v4');

function convertToNullIfUndefined<T>(arg: T): T|null {
return arg ? arg : null;
}

async function run() {
try {
tl.setResourcePath(path.join(__dirname, 'task.json'));
Expand All @@ -22,18 +26,16 @@ async function run() {
default:
throw new Error(tl.loc('JS_InvalidErrorActionPreference', _vsts_input_errorActionPreference));
}

let scriptType: string = tl.getInput('ScriptType', /*required*/true);
let scriptPath = tl.getPathInput('ScriptPath', false);
let scriptInline: string = tl.getInput('Inline', false);
let scriptArguments: string = tl.getInput('ScriptArguments', false);
let _vsts_input_failOnStandardError = tl.getBoolInput('FailOnStandardError', false);
let targetAzurePs: string = tl.getInput('TargetAzurePs', false);
let customTargetAzurePs: string = tl.getInput('CustomTargetAzurePs', false);
let scriptPath = convertToNullIfUndefined(tl.getPathInput('ScriptPath', false));
let scriptInline: string = convertToNullIfUndefined(tl.getInput('Inline', false));
let scriptArguments: string = convertToNullIfUndefined(tl.getInput('ScriptArguments', false));
let _vsts_input_failOnStandardError = convertToNullIfUndefined(tl.getBoolInput('FailOnStandardError', false));
let targetAzurePs: string = convertToNullIfUndefined(tl.getInput('TargetAzurePs', false));
let customTargetAzurePs: string = convertToNullIfUndefined(tl.getInput('CustomTargetAzurePs', false));
let serviceName = tl.getInput('ConnectedServiceNameARM',/*required*/true);
let endpointObject= await new AzureRMEndpoint(serviceName).getEndpoint();
let input_workingDirectory = tl.getPathInput('workingDirectory', /*required*/ true, /*check*/ true);

// string constants
let otherVersion = "OtherVersion"

Expand Down Expand Up @@ -63,7 +65,7 @@ async function run() {
console.log(tl.loc('GeneratingScript'));
let contents: string[] = [];
let azFilePath = path.join(path.resolve(__dirname), 'InitializeAz.ps1');
contents.push(`$ErrorActionPreference = '${_vsts_input_errorActionPreference}'`);
contents.push(`$ErrorActionPreference = '${_vsts_input_errorActionPreference}'`);
if(targetAzurePs == "") {
contents.push(`${azFilePath} -endpoint '${endpoint}'`);
}
Expand All @@ -89,14 +91,15 @@ async function run() {
let tempDirectory = tl.getVariable('agent.tempDirectory');
tl.checkPath(tempDirectory, `${tempDirectory} (agent.tempDirectory)`);
let filePath = path.join(tempDirectory, uuidV4() + '.ps1');

await fs.writeFile(
filePath,
'\ufeff' + contents.join(os.EOL), // Prepend the Unicode BOM character.
{ encoding: 'utf8' }); // Since UTF8 encoding is specified, node will
// encode the BOM into its UTF8 binary sequence.
{ encoding: 'utf8' }, // Since UTF8 encoding is specified, node will
function (err) { // encode the BOM into its UTF8 binary sequence.
if (err) throw err;
console.log('Saved!');
});
console.log("## Az module initialization Complete");

console.log("## Beginning Script Execution");
// Run the script.
//
Expand Down Expand Up @@ -152,4 +155,5 @@ async function run() {
}
}


run();
5 changes: 0 additions & 5 deletions Tasks/AzurePowerShellV4/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
{
"module": "../Common/TlsHelper_",
"type": "ps"
},
{
"module": "../Common/utility-common-v2",
"type": "node",
"compile": true
}
],
"externals": {
Expand Down
Loading

0 comments on commit c28f82e

Please sign in to comment.