<p>I am trying to delete all namespaces prefixed with &quot;dev-...&quot;. The command works fine on the commandline, but I'm not sure how to get this working in Azure Pipelines.</p>
<pre><code>kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep dev- | xargs kubectl delete namespace
</code></pre>

TechnicalFreak
<p>Hi below pipeline should work with a defined service principal.</p>
<pre><code>trigger: none

pool:
  vmImage: 'ubuntu-latest'

steps:

# Delete All namespaces start with dev-
- task: AzureCLI@2
  inputs:
    azureSubscription: 'YOUR_SUBSCRIPTION_SP'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az aks get-credentials --resource-group $AKS_RG --name $AKS_NAME --admin
      kubectl get ns
      kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep dev- | xargs kubectl delete namespace
      kubectl get ns
  displayName: 'Delete All namespaces start with dev-'
</code></pre>
