Skip to content

Commit

Permalink
Adding connected service input in MavevV4 task (#20402)
Browse files Browse the repository at this point in the history
Co-authored-by: Bhavesh Bhati <bhatibhavesh@microsoft.com>
  • Loading branch information
bhaveshbhati and Bhavesh Bhati authored Sep 11, 2024
1 parent ada25f7 commit d7d1b94
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 16 deletions.
21 changes: 21 additions & 0 deletions Tasks/MavenV4/maventask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ async function execBuild() {
// 5. Always publish test results even if tests fail, causing this task to fail.
// 6. If #3 or #4 above failed, exit with an error code to mark the entire step as failed.

setUpConnectedServiceEnvironmentVariables();

ccReportDir = await execEnableCodeCoverage();
var userRunFailed: boolean = false;
var codeAnalysisFailed: boolean = false;
Expand Down Expand Up @@ -653,4 +655,23 @@ function replaceImageSourceToBase64(dir: string): void {
}
}

function setUpConnectedServiceEnvironmentVariables() {
var connectedService = tl.getInput('ConnectedServiceName');
if(connectedService) {
var authScheme: string = tl.getEndpointAuthorizationScheme(connectedService, false);
if (authScheme && authScheme.toLowerCase() == "workloadidentityfederation") {
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
process.env.AZURESUBSCRIPTION_CLIENT_ID = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
process.env.AZURESUBSCRIPTION_TENANT_ID = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
tl.debug('Environment variables AZURESUBSCRIPTION_SERVICE_CONNECTION_ID,AZURESUBSCRIPTION_CLIENT_ID and AZURESUBSCRIPTION_TENANT_ID are set');
}
else {
tl.warning('Connected service is not of type Workload Identity Federation');
}
}
else {
tl.debug('No connected service set');
}
}

execBuildWithRestore();
12 changes: 11 additions & 1 deletion Tasks/MavenV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 245,
"Patch": 0
"Patch": 2
},
"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`",
"demands": [
Expand Down Expand Up @@ -49,6 +49,16 @@
}
],
"inputs": [
{
"name": "ConnectedServiceName",
"aliases": [
"azureSubscription"
],
"type": "connectedService:AzureRM",
"label": "Azure Resource Manager connection",
"defaultValue": "",
"helpMarkDown": "Select an Azure Resource Manager service connection"
},
{
"name": "mavenPOMFile",
"aliases": [
Expand Down
12 changes: 11 additions & 1 deletion Tasks/MavenV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 245,
"Patch": 0
"Patch": 2
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"demands": [
Expand Down Expand Up @@ -49,6 +49,16 @@
}
],
"inputs": [
{
"name": "ConnectedServiceName",
"aliases": [
"azureSubscription"
],
"type": "connectedService:AzureRM",
"label": "ms-resource:loc.input.label.ConnectedServiceName",
"defaultValue": "",
"helpMarkDown": "ms-resource:loc.input.help.ConnectedServiceName"
},
{
"name": "mavenPOMFile",
"aliases": [
Expand Down
4 changes: 2 additions & 2 deletions _generated/MavenV4.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|4.245.0
Node20-225|4.245.1
Default|4.245.2
Node20-225|4.245.3
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"loc.group.displayName.codeCoverage": "Code Coverage",
"loc.group.displayName.advanced": "Advanced",
"loc.group.displayName.CodeAnalysis": "Code Analysis",
"loc.input.label.ConnectedServiceName": "Azure Resource Manager connection",
"loc.input.help.ConnectedServiceName": "Select an Azure Resource Manager service connection",
"loc.input.label.mavenPOMFile": "Maven POM file",
"loc.input.help.mavenPOMFile": "Relative path from the repository root to the Maven POM file.",
"loc.input.label.goals": "Goal(s)",
Expand Down
21 changes: 21 additions & 0 deletions _generated/MavenV4/maventask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ async function execBuild() {
// 5. Always publish test results even if tests fail, causing this task to fail.
// 6. If #3 or #4 above failed, exit with an error code to mark the entire step as failed.

setUpConnectedServiceEnvironmentVariables();

ccReportDir = await execEnableCodeCoverage();
var userRunFailed: boolean = false;
var codeAnalysisFailed: boolean = false;
Expand Down Expand Up @@ -653,4 +655,23 @@ function replaceImageSourceToBase64(dir: string): void {
}
}

function setUpConnectedServiceEnvironmentVariables() {
var connectedService = tl.getInput('ConnectedServiceName');
if(connectedService) {
var authScheme: string = tl.getEndpointAuthorizationScheme(connectedService, false);
if (authScheme && authScheme.toLowerCase() == "workloadidentityfederation") {
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
process.env.AZURESUBSCRIPTION_CLIENT_ID = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
process.env.AZURESUBSCRIPTION_TENANT_ID = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
tl.debug('Environment variables AZURESUBSCRIPTION_SERVICE_CONNECTION_ID,AZURESUBSCRIPTION_CLIENT_ID and AZURESUBSCRIPTION_TENANT_ID are set');
}
else {
tl.warning('Connected service is not of type Workload Identity Federation');
}
}
else {
tl.debug('No connected service set');
}
}

execBuildWithRestore();
16 changes: 13 additions & 3 deletions _generated/MavenV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 245,
"Patch": 0
"Patch": 2
},
"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`",
"demands": [
Expand Down Expand Up @@ -49,6 +49,16 @@
}
],
"inputs": [
{
"name": "ConnectedServiceName",
"aliases": [
"azureSubscription"
],
"type": "connectedService:AzureRM",
"label": "Azure Resource Manager connection",
"defaultValue": "",
"helpMarkDown": "Select an Azure Resource Manager service connection"
},
{
"name": "mavenPOMFile",
"aliases": [
Expand Down Expand Up @@ -517,7 +527,7 @@
"NoTestResults": "No test result files matching %s were found, so publishing JUnit test results is being skipped."
},
"_buildConfigMapping": {
"Default": "4.245.0",
"Node20-225": "4.245.1"
"Default": "4.245.2",
"Node20-225": "4.245.3"
}
}
16 changes: 13 additions & 3 deletions _generated/MavenV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 245,
"Patch": 0
"Patch": 2
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"demands": [
Expand Down Expand Up @@ -49,6 +49,16 @@
}
],
"inputs": [
{
"name": "ConnectedServiceName",
"aliases": [
"azureSubscription"
],
"type": "connectedService:AzureRM",
"label": "ms-resource:loc.input.label.ConnectedServiceName",
"defaultValue": "",
"helpMarkDown": "ms-resource:loc.input.help.ConnectedServiceName"
},
{
"name": "mavenPOMFile",
"aliases": [
Expand Down Expand Up @@ -517,7 +527,7 @@
"NoTestResults": "ms-resource:loc.messages.NoTestResults"
},
"_buildConfigMapping": {
"Default": "4.245.0",
"Node20-225": "4.245.1"
"Default": "4.245.2",
"Node20-225": "4.245.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"loc.group.displayName.codeCoverage": "Code Coverage",
"loc.group.displayName.advanced": "Advanced",
"loc.group.displayName.CodeAnalysis": "Code Analysis",
"loc.input.label.ConnectedServiceName": "Azure Resource Manager connection",
"loc.input.help.ConnectedServiceName": "Select an Azure Resource Manager service connection",
"loc.input.label.mavenPOMFile": "Maven POM file",
"loc.input.help.mavenPOMFile": "Relative path from the repository root to the Maven POM file.",
"loc.input.label.goals": "Goal(s)",
Expand Down
21 changes: 21 additions & 0 deletions _generated/MavenV4_Node20/maventask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ async function execBuild() {
// 5. Always publish test results even if tests fail, causing this task to fail.
// 6. If #3 or #4 above failed, exit with an error code to mark the entire step as failed.

setUpConnectedServiceEnvironmentVariables();

ccReportDir = await execEnableCodeCoverage();
var userRunFailed: boolean = false;
var codeAnalysisFailed: boolean = false;
Expand Down Expand Up @@ -653,4 +655,23 @@ function replaceImageSourceToBase64(dir: string): void {
}
}

function setUpConnectedServiceEnvironmentVariables() {
var connectedService = tl.getInput('ConnectedServiceName');
if(connectedService) {
var authScheme: string = tl.getEndpointAuthorizationScheme(connectedService, false);
if (authScheme && authScheme.toLowerCase() == "workloadidentityfederation") {
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
process.env.AZURESUBSCRIPTION_CLIENT_ID = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
process.env.AZURESUBSCRIPTION_TENANT_ID = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
tl.debug('Environment variables AZURESUBSCRIPTION_SERVICE_CONNECTION_ID,AZURESUBSCRIPTION_CLIENT_ID and AZURESUBSCRIPTION_TENANT_ID are set');
}
else {
tl.warning('Connected service is not of type Workload Identity Federation');
}
}
else {
tl.debug('No connected service set');
}
}

execBuildWithRestore();
16 changes: 13 additions & 3 deletions _generated/MavenV4_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 245,
"Patch": 1
"Patch": 3
},
"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`",
"demands": [
Expand Down Expand Up @@ -49,6 +49,16 @@
}
],
"inputs": [
{
"name": "ConnectedServiceName",
"aliases": [
"azureSubscription"
],
"type": "connectedService:AzureRM",
"label": "Azure Resource Manager connection",
"defaultValue": "",
"helpMarkDown": "Select an Azure Resource Manager service connection"
},
{
"name": "mavenPOMFile",
"aliases": [
Expand Down Expand Up @@ -521,7 +531,7 @@
"NoTestResults": "No test result files matching %s were found, so publishing JUnit test results is being skipped."
},
"_buildConfigMapping": {
"Default": "4.245.0",
"Node20-225": "4.245.1"
"Default": "4.245.2",
"Node20-225": "4.245.3"
}
}
16 changes: 13 additions & 3 deletions _generated/MavenV4_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 245,
"Patch": 1
"Patch": 3
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"demands": [
Expand Down Expand Up @@ -49,6 +49,16 @@
}
],
"inputs": [
{
"name": "ConnectedServiceName",
"aliases": [
"azureSubscription"
],
"type": "connectedService:AzureRM",
"label": "ms-resource:loc.input.label.ConnectedServiceName",
"defaultValue": "",
"helpMarkDown": "ms-resource:loc.input.help.ConnectedServiceName"
},
{
"name": "mavenPOMFile",
"aliases": [
Expand Down Expand Up @@ -521,7 +531,7 @@
"NoTestResults": "ms-resource:loc.messages.NoTestResults"
},
"_buildConfigMapping": {
"Default": "4.245.0",
"Node20-225": "4.245.1"
"Default": "4.245.2",
"Node20-225": "4.245.3"
}
}

0 comments on commit d7d1b94

Please sign in to comment.