Skip to content

Commit d7d1b94

Browse files
bhaveshbhatiBhavesh Bhati
andauthored
Adding connected service input in MavevV4 task (#20402)
Co-authored-by: Bhavesh Bhati <[email protected]>
1 parent ada25f7 commit d7d1b94

File tree

12 files changed

+143
-16
lines changed

12 files changed

+143
-16
lines changed

Tasks/MavenV4/maventask.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ async function execBuild() {
140140
// 5. Always publish test results even if tests fail, causing this task to fail.
141141
// 6. If #3 or #4 above failed, exit with an error code to mark the entire step as failed.
142142

143+
setUpConnectedServiceEnvironmentVariables();
144+
143145
ccReportDir = await execEnableCodeCoverage();
144146
var userRunFailed: boolean = false;
145147
var codeAnalysisFailed: boolean = false;
@@ -653,4 +655,23 @@ function replaceImageSourceToBase64(dir: string): void {
653655
}
654656
}
655657

658+
function setUpConnectedServiceEnvironmentVariables() {
659+
var connectedService = tl.getInput('ConnectedServiceName');
660+
if(connectedService) {
661+
var authScheme: string = tl.getEndpointAuthorizationScheme(connectedService, false);
662+
if (authScheme && authScheme.toLowerCase() == "workloadidentityfederation") {
663+
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
664+
process.env.AZURESUBSCRIPTION_CLIENT_ID = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
665+
process.env.AZURESUBSCRIPTION_TENANT_ID = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
666+
tl.debug('Environment variables AZURESUBSCRIPTION_SERVICE_CONNECTION_ID,AZURESUBSCRIPTION_CLIENT_ID and AZURESUBSCRIPTION_TENANT_ID are set');
667+
}
668+
else {
669+
tl.warning('Connected service is not of type Workload Identity Federation');
670+
}
671+
}
672+
else {
673+
tl.debug('No connected service set');
674+
}
675+
}
676+
656677
execBuildWithRestore();

Tasks/MavenV4/task.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 4,
2020
"Minor": 245,
21-
"Patch": 0
21+
"Patch": 2
2222
},
2323
"releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`",
2424
"demands": [
@@ -49,6 +49,16 @@
4949
}
5050
],
5151
"inputs": [
52+
{
53+
"name": "ConnectedServiceName",
54+
"aliases": [
55+
"azureSubscription"
56+
],
57+
"type": "connectedService:AzureRM",
58+
"label": "Azure Resource Manager connection",
59+
"defaultValue": "",
60+
"helpMarkDown": "Select an Azure Resource Manager service connection"
61+
},
5262
{
5363
"name": "mavenPOMFile",
5464
"aliases": [

Tasks/MavenV4/task.loc.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 4,
2020
"Minor": 245,
21-
"Patch": 0
21+
"Patch": 2
2222
},
2323
"releaseNotes": "ms-resource:loc.releaseNotes",
2424
"demands": [
@@ -49,6 +49,16 @@
4949
}
5050
],
5151
"inputs": [
52+
{
53+
"name": "ConnectedServiceName",
54+
"aliases": [
55+
"azureSubscription"
56+
],
57+
"type": "connectedService:AzureRM",
58+
"label": "ms-resource:loc.input.label.ConnectedServiceName",
59+
"defaultValue": "",
60+
"helpMarkDown": "ms-resource:loc.input.help.ConnectedServiceName"
61+
},
5262
{
5363
"name": "mavenPOMFile",
5464
"aliases": [

_generated/MavenV4.versionmap.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Default|4.245.0
2-
Node20-225|4.245.1
1+
Default|4.245.2
2+
Node20-225|4.245.3

_generated/MavenV4/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"loc.group.displayName.codeCoverage": "Code Coverage",
99
"loc.group.displayName.advanced": "Advanced",
1010
"loc.group.displayName.CodeAnalysis": "Code Analysis",
11+
"loc.input.label.ConnectedServiceName": "Azure Resource Manager connection",
12+
"loc.input.help.ConnectedServiceName": "Select an Azure Resource Manager service connection",
1113
"loc.input.label.mavenPOMFile": "Maven POM file",
1214
"loc.input.help.mavenPOMFile": "Relative path from the repository root to the Maven POM file.",
1315
"loc.input.label.goals": "Goal(s)",

_generated/MavenV4/maventask.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ async function execBuild() {
140140
// 5. Always publish test results even if tests fail, causing this task to fail.
141141
// 6. If #3 or #4 above failed, exit with an error code to mark the entire step as failed.
142142

143+
setUpConnectedServiceEnvironmentVariables();
144+
143145
ccReportDir = await execEnableCodeCoverage();
144146
var userRunFailed: boolean = false;
145147
var codeAnalysisFailed: boolean = false;
@@ -653,4 +655,23 @@ function replaceImageSourceToBase64(dir: string): void {
653655
}
654656
}
655657

658+
function setUpConnectedServiceEnvironmentVariables() {
659+
var connectedService = tl.getInput('ConnectedServiceName');
660+
if(connectedService) {
661+
var authScheme: string = tl.getEndpointAuthorizationScheme(connectedService, false);
662+
if (authScheme && authScheme.toLowerCase() == "workloadidentityfederation") {
663+
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
664+
process.env.AZURESUBSCRIPTION_CLIENT_ID = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
665+
process.env.AZURESUBSCRIPTION_TENANT_ID = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
666+
tl.debug('Environment variables AZURESUBSCRIPTION_SERVICE_CONNECTION_ID,AZURESUBSCRIPTION_CLIENT_ID and AZURESUBSCRIPTION_TENANT_ID are set');
667+
}
668+
else {
669+
tl.warning('Connected service is not of type Workload Identity Federation');
670+
}
671+
}
672+
else {
673+
tl.debug('No connected service set');
674+
}
675+
}
676+
656677
execBuildWithRestore();

_generated/MavenV4/task.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 4,
2020
"Minor": 245,
21-
"Patch": 0
21+
"Patch": 2
2222
},
2323
"releaseNotes": "Configuration of the SonarQube analysis was moved to the [SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube) or [SonarCloud](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) extensions, in task `Prepare Analysis Configuration`",
2424
"demands": [
@@ -49,6 +49,16 @@
4949
}
5050
],
5151
"inputs": [
52+
{
53+
"name": "ConnectedServiceName",
54+
"aliases": [
55+
"azureSubscription"
56+
],
57+
"type": "connectedService:AzureRM",
58+
"label": "Azure Resource Manager connection",
59+
"defaultValue": "",
60+
"helpMarkDown": "Select an Azure Resource Manager service connection"
61+
},
5262
{
5363
"name": "mavenPOMFile",
5464
"aliases": [
@@ -517,7 +527,7 @@
517527
"NoTestResults": "No test result files matching %s were found, so publishing JUnit test results is being skipped."
518528
},
519529
"_buildConfigMapping": {
520-
"Default": "4.245.0",
521-
"Node20-225": "4.245.1"
530+
"Default": "4.245.2",
531+
"Node20-225": "4.245.3"
522532
}
523533
}

_generated/MavenV4/task.loc.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 4,
2020
"Minor": 245,
21-
"Patch": 0
21+
"Patch": 2
2222
},
2323
"releaseNotes": "ms-resource:loc.releaseNotes",
2424
"demands": [
@@ -49,6 +49,16 @@
4949
}
5050
],
5151
"inputs": [
52+
{
53+
"name": "ConnectedServiceName",
54+
"aliases": [
55+
"azureSubscription"
56+
],
57+
"type": "connectedService:AzureRM",
58+
"label": "ms-resource:loc.input.label.ConnectedServiceName",
59+
"defaultValue": "",
60+
"helpMarkDown": "ms-resource:loc.input.help.ConnectedServiceName"
61+
},
5262
{
5363
"name": "mavenPOMFile",
5464
"aliases": [
@@ -517,7 +527,7 @@
517527
"NoTestResults": "ms-resource:loc.messages.NoTestResults"
518528
},
519529
"_buildConfigMapping": {
520-
"Default": "4.245.0",
521-
"Node20-225": "4.245.1"
530+
"Default": "4.245.2",
531+
"Node20-225": "4.245.3"
522532
}
523533
}

_generated/MavenV4_Node20/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"loc.group.displayName.codeCoverage": "Code Coverage",
99
"loc.group.displayName.advanced": "Advanced",
1010
"loc.group.displayName.CodeAnalysis": "Code Analysis",
11+
"loc.input.label.ConnectedServiceName": "Azure Resource Manager connection",
12+
"loc.input.help.ConnectedServiceName": "Select an Azure Resource Manager service connection",
1113
"loc.input.label.mavenPOMFile": "Maven POM file",
1214
"loc.input.help.mavenPOMFile": "Relative path from the repository root to the Maven POM file.",
1315
"loc.input.label.goals": "Goal(s)",

_generated/MavenV4_Node20/maventask.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ async function execBuild() {
140140
// 5. Always publish test results even if tests fail, causing this task to fail.
141141
// 6. If #3 or #4 above failed, exit with an error code to mark the entire step as failed.
142142

143+
setUpConnectedServiceEnvironmentVariables();
144+
143145
ccReportDir = await execEnableCodeCoverage();
144146
var userRunFailed: boolean = false;
145147
var codeAnalysisFailed: boolean = false;
@@ -653,4 +655,23 @@ function replaceImageSourceToBase64(dir: string): void {
653655
}
654656
}
655657

658+
function setUpConnectedServiceEnvironmentVariables() {
659+
var connectedService = tl.getInput('ConnectedServiceName');
660+
if(connectedService) {
661+
var authScheme: string = tl.getEndpointAuthorizationScheme(connectedService, false);
662+
if (authScheme && authScheme.toLowerCase() == "workloadidentityfederation") {
663+
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
664+
process.env.AZURESUBSCRIPTION_CLIENT_ID = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
665+
process.env.AZURESUBSCRIPTION_TENANT_ID = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
666+
tl.debug('Environment variables AZURESUBSCRIPTION_SERVICE_CONNECTION_ID,AZURESUBSCRIPTION_CLIENT_ID and AZURESUBSCRIPTION_TENANT_ID are set');
667+
}
668+
else {
669+
tl.warning('Connected service is not of type Workload Identity Federation');
670+
}
671+
}
672+
else {
673+
tl.debug('No connected service set');
674+
}
675+
}
676+
656677
execBuildWithRestore();

0 commit comments

Comments
 (0)