diff --git a/Tasks/AzureKeyVault/operations/KeyVault.ts b/Tasks/AzureKeyVault/operations/KeyVault.ts index 1c5ec276bf02..168737765752 100644 --- a/Tasks/AzureKeyVault/operations/KeyVault.ts +++ b/Tasks/AzureKeyVault/operations/KeyVault.ts @@ -154,7 +154,7 @@ Set-AzureRmKeyVaultAccessPolicy -VaultName %s -ObjectId $spnObjectId -Permission secretsToErrorsMap.addError(secretName, errorMessage); } else { - tl.setVariable(secretName, secretValue, true); + this.setVaultVariable(secretName, secretValue); } return resolve(); @@ -162,6 +162,45 @@ Set-AzureRmKeyVaultAccessPolicy -VaultName %s -ObjectId $spnObjectId -Permission }); } + private tryFlattenJson(jsonString: string): string { + try { + var o = JSON.parse(jsonString); + + if (o && typeof o === "object") { + return JSON.stringify(o); + } + } + catch (e) { } + + return null; + } + + private setVaultVariable(secretName: string, secretValue: string): void { + if (!secretValue) { + return; + } + + if (secretValue.indexOf('\n') < 0) { + // single-line case + tl.setVariable(secretName, secretValue, true); + } + else { + // multi-line case + let strVal = this.tryFlattenJson(secretValue); + if (strVal) { + console.log(util.format("Value of secret %s has been converted to single line.", secretName)); + tl.setVariable(secretName, strVal, true); + } + else { + let lines = secretValue.split('\n'); + lines.forEach((line: string, index: number) => { + console.log("##vso[task.setsecret]" + line); + }); + tl.setVariable(secretName, secretValue, true); + } + } + } + private getError(error: any): any { tl.debug(JSON.stringify(error)); diff --git a/Tasks/AzureKeyVault/task.json b/Tasks/AzureKeyVault/task.json index ea36779a195b..5ad210e08814 100644 --- a/Tasks/AzureKeyVault/task.json +++ b/Tasks/AzureKeyVault/task.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 14 + "Patch": 15 }, "demands": [], "minimumAgentVersion": "2.0.0", diff --git a/Tasks/AzureKeyVault/task.loc.json b/Tasks/AzureKeyVault/task.loc.json index 6aca4256d52d..95edea1666d8 100644 --- a/Tasks/AzureKeyVault/task.loc.json +++ b/Tasks/AzureKeyVault/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 14 + "Patch": 15 }, "demands": [], "minimumAgentVersion": "2.0.0",