1
votes

​Hello all

​I've added all the IP range listed in https://devblogs.microsoft.com/devops/new-ip-firewall-rules-for-azure-devops/ into my firewall. But still im not able to run powershell command from azure devops pipeline YAML to my on-premises windows server. Every time im getting new IP from microsoft, and that are not listed in above mentioned site.

Im able to connect to server with my local machine using below powershell command

below is my yaml pipeline script

pool:
vmImage: 'windows-latest'

stages:
- stage: 'Deploy'
  jobs:
- deployment: 'Deploy'
environment: 'stage'
strategy:
  runOnce:
    deploy:
      steps:
      - task: PowerShell@2
        inputs:
          targetType: 'inline'
          script: |
            $so = New-PsSessionOption –SkipCACheck -SkipCNCheck
            $username='myUserName'
            $password='myPassword'
            $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
            $credentials = New-Object System.Management.Automation.PSCredential($username, $secpasswd)
            Enter-PSSession -ComputerName xyz.com -Credential $credentials -UseSSL -SessionOption $so
            write-output 'host name is '+$(hostname)

Im getting error :

Enter-PSSession : Connecting to remote server xyz.com failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting.

Is it issue releated to firewall or my approach is wrong to execute Powershell script using azure devops?

1
Hi You probably need to create your self-hosted agent, since the on-premises remote server is not accessible to Microsoft cloud agents. See below answerLevi Lu-MSFT

1 Answers

0
votes

Your on-premises remote server is not accessible to Microsoft cloud agents. You cannot connect to your on-premises remote server if you run your pipeline on Microsoft cloud agents. Unless your on-premises remote server can be accessed from public network.

Since you are able to connect to on-premise server with your local machine. You can create a self-hosted agent on your local machine. And run your deployment job on this self-hosted agent by specify the pool to your local agent pool for the deployment job. Then you will be able to connect to the remote local server. See below

- deployment: Deploy
  displayName: deploy Web App
  #specify the local agent pool to run deployment job on self-hosted agent
  pool: default
  environment: stage
  strategy: