<p>We're building out a release pipeline in Azure DevOps which pushes to a Kubernetes cluster. The first step in the pipeline is to run an Azure CLI script which sets up all the resources - this is an idempotent script so we can run it each time we run the release pipeline. Our intention is to have a standardised release pipeline which we can run against several clusters, existing and new.</p>
<p>The final step in the pipeline is to run the Kubectl task with the <code>apply</code> command.</p>
<p>However, this pipeline task requires specifying in advance (at the time of building the pipeline) the names of the resource group and cluster against which it should be executed. But the point of the idempotent script in the first step is to ensure that the resources and to create if not.</p>
<p>So there's the possibility that neither the resource group nor the cluster will exist before the pipeline is run.</p>
<p>How can I achieve this in a DevOps pipeline if the Kubectl task requires a resource group and a cluster to be specified at design time?</p>
<p><a href="https://i.stack.imgur.com/uTNyV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uTNyV.png" alt="enter image description here" /></a></p>

awj
<p>This <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes?view=azure-devops" rel="nofollow noreferrer">Kubectl task</a> works with service connection type: <strong>Azure Resource Manager</strong>. And it requires to select Resource group field and Kubernetes cluster field after you select the Azure subscription, as below.
<a href="https://i.stack.imgur.com/QLOqP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QLOqP.png" alt="enter image description here" /></a></p>
<p>After testing, we find that these 2 fields supports variable. Thus you could use variable in these 2 fields, and using <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/powershell?view=azure-devops" rel="nofollow noreferrer">PowerShell task</a> to set variable value before this <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes?view=azure-devops" rel="nofollow noreferrer">Kubectl task</a>. See: <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&amp;tabs=yaml%2Cbatch#set-variables-in-scripts" rel="nofollow noreferrer">Set variables in scripts</a> for details.</p>
