Skip to content

Conversation

tpavlovi
Copy link
Contributor

@tpavlovi tpavlovi commented Aug 15, 2025

Context

The new version of the task for Azure CLI supports Azure DevOps service connections. Regarding the ARM connection type, everything remains the same as in AzureCLI v2. However, when using Azure DevOps service connections, the following occurs:

  • Automatic extension installation: Installs the azure-devops CLI extension
  • Organization/Project configuration: Automatically configures the default organization and project based on the pipeline context

Task Name

AzureCLIV3


Description

Added new connectionType input with options:

  • azureRM (default)
  • azureDevOps - New support for Azure DevOps service connections

Method setupAzureDevOpsCLI():

  • Automatic extension installation: az extension add -n azure-devops -y
  • Workload Identity Federation authentication for Azure DevOps connections
  • Organization/project auto-configuration from pipeline context variables
  • Environment variable setup for Azure DevOps scenarios
az extension add -n azure-devops -y
az login --service-principal -u "{servicePrincipalId}" --tenant "{tenantId}" --allow-no-subscriptions --federated-token "{federatedToken}"
az devops configure --defaults organization="{org}" project="{project}"

New error messages:

  • FailedToInstallAzureDevOpsCLI - "Failed to install Azure DevOps CLI extension",
  • FailedToSetAzureDevOpsOrganization - "Failed to set Azure DevOps organization",
  • FailedToSetAzureDevOpsProject - "Failed to set Azure DevOps project"

Risk Assessment (Low / Medium / High)

Assess the level of risk and provide reasoning (e.g., scope, impact, backward compatibility).


Change Behind Feature Flag (Yes/No)

There’s no need to add a feature flag. If needed, the user can switch to V2.


Tech Design / Approach


Documentation Changes Required (Yes/No)

Yes


Unit Tests Added or Updated (Yes/No)

No


Additional Testing Performed

The task has been tested within the organization on Ring-1 and in DevFabric


Logging Added/Updated (Yes/No)

Yes


Telemetry Added/Updated (Yes/No)

No


Rollback Scenario and Process (Yes/No)

If a rollback is needed, the user can switch to a different task version


Dependency Impact Assessed and Regression Tested (Yes/No)

No


Checklist

  • Related issue linked (if applicable)
  • Task version was bumped — see versioning guide
  • Verified the task behaves as expected

Utility.throwIfError(tl.execSync("az", `devops configure --defaults project="${project}"`), tl.loc("FailedToSetAzureDevOpsProject"));
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the indentation here for closing curly bracet.
Also I recommend throwing an error here if authScheme.toLowerCase() != "workloadidentityfederation"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. I’ve added an error for that case

if (project) {
Utility.throwIfError(tl.execSync("az", `devops configure --defaults project="${project}"`), tl.loc("FailedToSetAzureDevOpsProject"));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant empty line here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, thank you!

tl.setSecret(federatedToken);
let args = `login --service-principal -u "${servicePrincipalId}" --tenant "${tenantId}" --allow-no-subscriptions --federated-token "${federatedToken}"`;

if(!visibleAzLogin ){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add white spaces for If (...) condition - like it's done in in this method below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

White spaces added, thank you!

@tpavlovi tpavlovi changed the title Added AzureCLIV3 AzureCLI V3 task with Azure DevOps Service Connection support Aug 15, 2025
Copy link
Contributor

@onetocny onetocny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR. Please take a look at my comments. I highly recommend introducing unit tests before we release this task.

const project = tl.getVariable('System.TeamProject');

if (organization) {
Utility.throwIfError(tl.execSync("az", `devops configure --defaults organization="${organization}"`), tl.loc("FailedToSetAzureDevOpsOrganization"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not we clean these settings once the task is completed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be okay to proceed like this?
az devops configure --defaults organization='' project=''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

});

it('Does a basic hello world test', function (done: MochaDone) {
// TODO - add real tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add some real tests. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, tests have been added!

{
"name": "azure-cli-tests",
"version": "1.0.0",
"description": "Azure Pipelines Azure CLI V2 Task Tests",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it still says V2. Maybe check the whole folder for unintentional mentions of V2 where V3 needs to be used instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants