I want to reset the password of SQL server through Azure pipeline. I don't have access to change the password manually in Azure portal/CLI/Powershell.

Chandra Vamsi Tiruveedula 0 Reputation points
2026-08-21T03:09:08.1666667+00:00
  • Currently, I'm trying to reset the password using Azure pipeline.
  • There is already an existing pipeline running.
  • So, to reset the password, how can I include my script inside that pipeline yml script.
  • Here, I was stuck. Can anyone help me on this?
Azure DevOps

1 answer

Sort by: Newest
  1. Allan Solomon Mejia 7,915 Reputation points
    2026-08-23T17:20:05.2633333+00:00

    Hello @Chandra Vamsi Tiruveedula

    Yes, you can reset an Azure SQL logical server administrator password from an Azure DevOps YAML pipeline. However, the pipeline still needs an identity that is authorized to modify that SQL server.

    In other words, if you personally don't have permission to reset the password through Portal, CLI, or PowerShell, putting the same operation inside a pipeline doesn't bypass Azure RBAC. The Azure Resource Manager service connection used by the pipeline must have the necessary permission on the SQL server or its resource group.

    Microsoft supports changing the administrator password using:

    az sql server update \
      --resource-group <resource-group> \
      --name <sql-server-name> \
      --admin-password "<new-password>"
    

    The az sql server update command specifically provides the --admin-password parameter for this purpose.

    Since you already have an Azure DevOps pipeline, you can execute it using an AzureCLI@2 task:

    variables:
      resourceGroup: 'my-resource-group'
      sqlServer: 'my-sql-server'
    steps:
    - task: AzureCLI@2
      displayName: 'Reset Azure SQL administrator password'
      inputs:
        azureSubscription: 'My-Azure-Service-Connection'
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: |
          az sql server update \
            --resource-group "$(resourceGroup)" \
            --name "$(sqlServer)" \
            --admin-password "$(SqlAdminPassword)"
    

    My-Azure-Service-Connection should be an authorized Azure Resource Manager service connection. Microsoft documents AzureCLI@2 specifically for running Azure CLI commands against an Azure subscription through such a connection.

    Do not put the password directly in the YAML file. Create SqlAdminPassword as a secret pipeline variable, variable-group secret, or preferably retrieve it from Azure Key Vault if that's part of your environment.

    The equivalent PowerShell operation is also supported:

    $securePassword = ConvertTo-SecureString "$(SqlAdminPassword)" -AsPlainText -Force
    Set-AzSqlServer `
        -ResourceGroupName "$(resourceGroup)" `
        -ServerName "$(sqlServer)" `
        -SqlAdministratorPassword $securePassword
    

    Microsoft documents Set-AzSqlServer specifically with an example for resetting the SQL server administrator password.

    The main issue in your case, though, is authorization.

    If your Azure DevOps service connection doesn't have permission to perform Microsoft.Sql/servers/write on that SQL server, the pipeline will fail even though the YAML is correct. You'll need your Azure administrator/subscription owner to grant the service connection's identity an appropriate role at the narrowest practical scope.

    I wouldn't recommend granting your personal account broader Azure access just to make this work. For automation, using a dedicated service connection with only the required permissions is the cleaner approach.

    Sharing these references with you:

    Microsoft – az sql server update

    Microsoft – Set-AzSqlServer

    Microsoft – AzureCLI@2 task

    Microsoft – Azure Resource Manager service connections

    If you can share what type of SQL Server this is (Azure SQL Database logical server, SQL Managed Instance, or SQL Server running inside an Azure VM) and what Azure service connection your existing pipeline uses, I can provide the exact YAML for that environment.

    Hope this helps. If this resolves your question, please consider "Accepting the Answer" so it can help others in the community.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.