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

Reuse az login output result to detect id version supports "--certificate" param or not #20701

Merged
merged 2 commits into from
Nov 29, 2024
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
17 changes: 11 additions & 6 deletions Tasks/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path = require("path");
import tl = require("azure-pipelines-task-lib/task");
import fs = require("fs");
import { IExecSyncResult } from 'azure-pipelines-task-lib/toolrunner';
import { Utility } from "./src/Utility";
import { ScriptType, ScriptTypeFactory } from "./src/ScriptType";
import { getSystemAccessToken } from 'azure-pipelines-tasks-artifacts-common/webapi';
Expand Down Expand Up @@ -49,7 +50,11 @@ export class azureclitask {
var failOnStdErr: boolean = tl.getBoolInput("failOnStandardError", false);
tl.mkdirP(cwd);
tl.cd(cwd);
Utility.throwIfError(tl.execSync("az", "--version"));

const azVersionResult: IExecSyncResult = tl.execSync("az", "--version");
Utility.throwIfError(azVersionResult);
this.isSupportCertificateParameter = this.isAzVersionGreaterOrEqual(azVersionResult.stdout, "2.66.0");

// set az cli config dir
this.setConfigDirectory();
this.setAzureCloudBasedOnServiceEndpoint();
Expand Down Expand Up @@ -192,14 +197,14 @@ export class azureclitask {
private static servicePrincipalKey: string = null;
private static federatedToken: string = null;
private static tenantId: string = null;
private static isSupportCertificateParameter: boolean = false;

private static isAzVersionGreaterOrEqual(versionToCompare) {
private static isAzVersionGreaterOrEqual(azVersionResultOutput, versionToCompare) {
try {
const result = tl.execSync("az", "--version");
const versionMatch = result.stdout.match(/azure-cli\s+(\d+\.\d+\.\d+)/);
const versionMatch = azVersionResultOutput.match(/azure-cli\s+(\d+\.\d+\.\d+)/);

if (!versionMatch || versionMatch.length < 2) {
tl.error(`Can't parse az version from: ${result}`);
tl.error(`Can't parse az version from: ${azVersionResultOutput}`);
return false;
}

Expand Down Expand Up @@ -263,7 +268,7 @@ export class azureclitask {

if (authType == "spnCertificate") {
tl.debug('certificate based endpoint');
if(azureclitask.isAzVersionGreaterOrEqual("2.66.0")) {
if(this.isSupportCertificateParameter) {
authParam = "--certificate";
}
let certificateContent: string = tl.getEndpointAuthorizationParameter(connectedService, "servicePrincipalCertificate", 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 @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 249,
"Patch": 5
"Patch": 7
},
"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 @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 249,
"Patch": 5
"Patch": 7
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
4 changes: 2 additions & 2 deletions _generated/AzureCLIV2.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|2.249.5
Node20_229_2|2.249.6
Default|2.249.7
Node20_229_2|2.249.8
17 changes: 11 additions & 6 deletions _generated/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path = require("path");
import tl = require("azure-pipelines-task-lib/task");
import fs = require("fs");
import { IExecSyncResult } from 'azure-pipelines-task-lib/toolrunner';
import { Utility } from "./src/Utility";
import { ScriptType, ScriptTypeFactory } from "./src/ScriptType";
import { getSystemAccessToken } from 'azure-pipelines-tasks-artifacts-common/webapi';
Expand Down Expand Up @@ -37,7 +38,11 @@ export class azureclitask {
var failOnStdErr: boolean = tl.getBoolInput("failOnStandardError", false);
tl.mkdirP(cwd);
tl.cd(cwd);
Utility.throwIfError(tl.execSync("az", "--version"));

const azVersionResult: IExecSyncResult = tl.execSync("az", "--version");
Utility.throwIfError(azVersionResult);
this.isSupportCertificateParameter = this.isAzVersionGreaterOrEqual(azVersionResult.stdout, "2.66.0");

// set az cli config dir
this.setConfigDirectory();
this.setAzureCloudBasedOnServiceEndpoint();
Expand Down Expand Up @@ -180,14 +185,14 @@ export class azureclitask {
private static servicePrincipalKey: string = null;
private static federatedToken: string = null;
private static tenantId: string = null;
private static isSupportCertificateParameter: boolean = false;

private static isAzVersionGreaterOrEqual(versionToCompare) {
private static isAzVersionGreaterOrEqual(azVersionResultOutput, versionToCompare) {
try {
const result = tl.execSync("az", "--version");
const versionMatch = result.stdout.match(/azure-cli\s+(\d+\.\d+\.\d+)/);
const versionMatch = azVersionResultOutput.match(/azure-cli\s+(\d+\.\d+\.\d+)/);

if (!versionMatch || versionMatch.length < 2) {
tl.error(`Can't parse az version from: ${result}`);
tl.error(`Can't parse az version from: ${azVersionResultOutput}`);
return false;
}

Expand Down Expand Up @@ -251,7 +256,7 @@ export class azureclitask {

if (authType == "spnCertificate") {
tl.debug('certificate based endpoint');
if(azureclitask.isAzVersionGreaterOrEqual("2.66.0")) {
if(this.isSupportCertificateParameter) {
authParam = "--certificate";
}
let certificateContent: string = tl.getEndpointAuthorizationParameter(connectedService, "servicePrincipalCertificate", false);
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 249,
"Patch": 5
"Patch": 7
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -226,7 +226,7 @@
"KeepingAzSessionActiveUnsupportedScheme": "The 'keepAzSessionActive' input might be used only for workload identity federation ARM service connection. The referenced service endpoint auth scheme was unexpected: %s. Change the scheme or remove 'keepAzSessionActive' input."
},
"_buildConfigMapping": {
"Default": "2.249.5",
"Node20_229_2": "2.249.6"
"Default": "2.249.7",
"Node20_229_2": "2.249.8"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 249,
"Patch": 5
"Patch": 7
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -226,7 +226,7 @@
"KeepingAzSessionActiveUnsupportedScheme": "ms-resource:loc.messages.KeepingAzSessionActiveUnsupportedScheme"
},
"_buildConfigMapping": {
"Default": "2.249.5",
"Node20_229_2": "2.249.6"
"Default": "2.249.7",
"Node20_229_2": "2.249.8"
}
}
17 changes: 11 additions & 6 deletions _generated/AzureCLIV2_Node20/azureclitask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path = require("path");
import tl = require("azure-pipelines-task-lib/task");
import fs = require("fs");
import { IExecSyncResult } from 'azure-pipelines-task-lib/toolrunner';
import { Utility } from "./src/Utility";
import { ScriptType, ScriptTypeFactory } from "./src/ScriptType";
import { getSystemAccessToken } from 'azure-pipelines-tasks-artifacts-common/webapi';
Expand Down Expand Up @@ -47,7 +48,11 @@ export class azureclitask {
var failOnStdErr: boolean = tl.getBoolInput("failOnStandardError", false);
tl.mkdirP(cwd);
tl.cd(cwd);
Utility.throwIfError(tl.execSync("az", "--version"));

const azVersionResult: IExecSyncResult = tl.execSync("az", "--version");
Utility.throwIfError(azVersionResult);
this.isSupportCertificateParameter = this.isAzVersionGreaterOrEqual(azVersionResult.stdout, "2.66.0");

// set az cli config dir
this.setConfigDirectory();
this.setAzureCloudBasedOnServiceEndpoint();
Expand Down Expand Up @@ -190,14 +195,14 @@ export class azureclitask {
private static servicePrincipalKey: string = null;
private static federatedToken: string = null;
private static tenantId: string = null;
private static isSupportCertificateParameter: boolean = false;

private static isAzVersionGreaterOrEqual(versionToCompare) {
private static isAzVersionGreaterOrEqual(azVersionResultOutput, versionToCompare) {
try {
const result = tl.execSync("az", "--version");
const versionMatch = result.stdout.match(/azure-cli\s+(\d+\.\d+\.\d+)/);
const versionMatch = azVersionResultOutput.match(/azure-cli\s+(\d+\.\d+\.\d+)/);

if (!versionMatch || versionMatch.length < 2) {
tl.error(`Can't parse az version from: ${result}`);
tl.error(`Can't parse az version from: ${azVersionResultOutput}`);
return false;
}

Expand Down Expand Up @@ -261,7 +266,7 @@ export class azureclitask {

if (authType == "spnCertificate") {
tl.debug('certificate based endpoint');
if(azureclitask.isAzVersionGreaterOrEqual("2.66.0")) {
if(this.isSupportCertificateParameter) {
authParam = "--certificate";
}
let certificateContent: string = tl.getEndpointAuthorizationParameter(connectedService, "servicePrincipalCertificate", false);
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 249,
"Patch": 6
"Patch": 8
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -230,7 +230,7 @@
"KeepingAzSessionActiveUnsupportedScheme": "The 'keepAzSessionActive' input might be used only for workload identity federation ARM service connection. The referenced service endpoint auth scheme was unexpected: %s. Change the scheme or remove 'keepAzSessionActive' input."
},
"_buildConfigMapping": {
"Default": "2.249.5",
"Node20_229_2": "2.249.6"
"Default": "2.249.7",
"Node20_229_2": "2.249.8"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 249,
"Patch": 6
"Patch": 8
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -230,7 +230,7 @@
"KeepingAzSessionActiveUnsupportedScheme": "ms-resource:loc.messages.KeepingAzSessionActiveUnsupportedScheme"
},
"_buildConfigMapping": {
"Default": "2.249.5",
"Node20_229_2": "2.249.6"
"Default": "2.249.7",
"Node20_229_2": "2.249.8"
}
}