'Jenkins active choice options populated with gke cluster namespaces

I am trying to create a Jenkins pipeline with active choice parameter options populated with GKE Cluster namespaces.

I can Run a single shell command and get output with this

def namespaces = "kubectl get ns".execute()
namespaces.waitFor()
def namespace_string = namespaces.text

But or this usecase I need to execute all below three shell commands in one process(authenticate cluster, switch to cluster, get namespaces) but seems they are not running in the same process

"sudo gcloud auth activate-service-account --key-file=key_file.json"
"gcloud container clusters get-credentials $CLUSTER --region $REGION --project $PROJECT"
"kubectl get ns"

Can anyone help with this? Please note that this is for populating active choice list.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source