Cannot run multiple kubectl commands using Azure Devops Pipeline Kubernetes@1 task

10/16/2019

I am trying to run multiple kubectl commands using Kubernetes@1 task in Azure Devops Pipeline, however I am not sure how to do this.

kubectl exec $(kubectl get pods -l app=deployment_label -o custom-columns=:metadata.name --namespace=some_name_space) --namespace=some_namespace -- some command

-- LightGuard
azure-devops
azure-pipelines
kubernetes

1 Answer

10/17/2019

If what you want is input these multiple commands into Command parameter of the task:

enter image description here

Unfortunately to say, No, the task script does not support this compiled method until now.

As the doc described:

enter image description here

The command input accept only one of these commands, which means you can only input one command in each Kubernetes@1 task.

Also, if you want to input instead of select one of commands from it, it could not exceed the range of commands allowed by this task and has restrict writing format like this:

enter image description here

For the commands you provided, if continue want to use Kubernetes@1 task, you'd better split these commands into the separate one with multiple tasks. You could check this blog for detailed usage.


As work around, if you still want to execute this multiple commands at same time, you can use Azure CLI task(if you are connecting Azure K8s), or use Command line task(if what you are connecting is the local k8s server).

-- Merlin Liang - MSFT
Source: StackOverflow