Search code examples
azureazure-devopskubectlazure-aks

How to pass the output from kubectl task to next task in Azure Devops


I am using AKS.I am trying to fetch the IP of the service post my deployment through devops so that I can pass on the IP to the API Management for further configuration. right now my task looks like this

               - task: Kubernetes@1
                  inputs:
                    connectionType: 'Kubernetes Service Connection'
                    kubernetesServiceEndpoint: 'string-Conn'
                    namespace: '<appservices>'
                    command: 'get'
                    arguments: 'get services --namespace appservices authsvc --output jsonpath=''{.status.loadBalancer.ingress[0].ip}'''
                    secretType: 'dockerRegistry'
                    containerRegistryType: 'Azure Container Registry'
                  name: 'GetSvc'

when I run the command locally I am getting the IP of the loadbalancer. but how can I pass the output from this task to the next task? previously, when I use azure cli scripts, I can pass the vso set variable as part of the script itself like the one below but not sure how will I add the output of this task to a variable.

inlineScript: |

$something = (az storage container generate-sas --account-name <container> --name armtemplate --permissions r --expiry $(date -u -d "30 minutes" +%Y-%m-%dT%H:%MZ))
                  Write-Host($something) Write-Output("##vso[task.setvariable variable=SasToken;]$something")

Solution

  • I have followed the approach suggested by Amit Baranes since I am not clear on the script execution assignment without variable name. I have used the Azure cli task and ran it. It was successful

              - task: AzureCLI@2
                  inputs:
                    azureSubscription: '<Service-Conn>'
                    scriptType: 'pscore'
                    scriptLocation: 'inlineScript'
                    inlineScript: |
                      az aks get-credentials -n $(clusterName) -g $(clusterRG)
                      $externalIp = (kubectl get -n $(ns) services $(svc) --output jsonpath='{.status.loadBalancer.ingress[0].ip}' )
                      Write-Host($externalIp) Write-Output("##vso[task.setvariable variable=AKSURL;]$externalIp")