'Azure devops - get agent ip address

I have a azure devops pipeline that runs 2 jobs - one on windows agent running a server, the other on Linux agent - running a client that connects to the server. These jobs run in parallel. Currently ip address and port are hard coded on client side repo. But I want to decouple this situation. is there a way in azure devops pipeline to get agent ip in the first job, store it in variable and use it as parameter to a step in the second job?

thanks a lot for all the help.



Solution 1:[1]

is there a way in azure devops pipeline to get agent ip in the first job, store it in variable and use it as parameter to a step in the second job?

As suggested by Anand Sowmithiran:

Use Get-NetIPAddress to get the ipinfo:

Get-NetIPAddress -AddressFamily IPv4

To use the first job parameter in a second job, you can set multi-job output variable

For example:

jobs:
# Set an output variable from job A
- job: A
  pool:
    vmImage: 'windows-latest'
  steps:
  - powershell: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value"
    name: setvarStep
  - script: echo $(setvarStep.myOutputVar)
    name: echovar

# Map the variable into job B
- job: B
  dependsOn: A
  pool:
    vmImage: 'ubuntu-18.04'
  variables:
    myVarFromJobA: $[ dependencies.A.outputs['setvarStep.myOutputVar'] ]  # map in the variable
                                                                          # remember, expressions require single quotes
  steps:
  - script: echo $(myVarFromJobA)
    name: echovar

Sources

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

Source: Stack Overflow

Solution Source
Solution 1