IISExpress not working

Hi,

https://ci.appveyor.com/project/JohnReilly/jquery-validation-unobtr...

My build runs a powershell script that, briefly, spins up the ASP.Net MVC project jVUNDemo using IISExpress:

write-host "Spin up jVUNDemo site"
Start-Job -Name RunIisExpress -Scriptblock {& 'C:\Program Files (x86)\IIS Express\iisexpress.exe' /path:$jVUNDemo /port:57612}

write-host "Wait a moment for IIS to startup"
Wait-Job -Name RunIisExpress -Timeout 5

if (Test-Path $staticSite) { 
    write-host "Removing $($staticSite)..."
    Remove-Item -path $staticSite -Recurse -Force
}

write-host "Create static version of demo site here: $($staticSite)"
Push-Location $staticSiteParent
wget.exe --recursive --convert-links -E --directory-prefix=static-site --no-host-directories http://localhost:57612/
Pop-Location

write-host "Shut down jVUNDemo site"
Receive-Job -Name RunIisExpress
Get-Job -Name RunIisExpress | Stop-Job
Get-Job -Name RunIisExpress | Remove-Job

It does this so we can use wget to generate a static site. We plan to use that to publish to GitHub Pages. However, whilst this runs fine locally (on my Windows 8.1 machine) it fails as part of the AppVeyor build:

wget.exe : --2014-12-16 16:05:28--  http://localhost:57612/
At C:\projects\jquery-validation-unobtrusive-native\makeStatic.ps1:23 char:1
+ wget.exe --recursive --convert-links -E --directory-prefix=static-site --no-host ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (--2014-12-16 16...ocalhost:57612/:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Resolving localhost... 
127.0.0.1
 
Connecting to localhost|127.0.0.1|:57612... 
failed: Connection refused.

It seems we cannot start IISExpress. Is there a way to rectify this?

  1. Might be too little timeout?

    I did a simple test here and it worked: https://ci.appveyor.com/project/appvyr/simple-console/build/1.0.52

  2. Thanks for the example Feodor. I upped my timeout to 30 seconds but it doesn't seem to have made a difference. I've been trying out different things but nothing seems to make a difference.

    Interestingly there appears to be a difference in how your job runs:

    Id     Name            PSJobTypeName   State         HasMoreData     Location             Command                  
    --     ----            -------------   -----         -----------     --------             -------                  
    1      RunIisExpress   BackgroundJob   Running       True            localhost            & 'C:\Program Files (x...
    

    And how mine runs:

    Id     Name            PSJobTypeName   State         HasMoreData     Location             Command                  
    --     ----            -------------   -----         -----------     --------             -------                  
    1      RunIisExpress   BackgroundJob   Completed     False           localhost            ...                      ```
    
    Note mine is "Completed".  Not sure why that would be.  Do you have any unusual settings set in your test project perhaps?
    

    param([string]$buildFolder)

    $jVUNDemo = "$($buildFolder)\jVUNDemo" $staticSiteParentPath = (get-item $buildFolder).Parent.FullName $staticSite = "static-site" $staticSitePath = "$($staticSiteParentPath)\$($staticSite)" $port = 57612 $servedAt = "http://localhost:$($port)/" write-host "jVUNDemo location: $jVUNDemo"
    write-host "static site parent location: $staticSiteParentPath"
    write-host "static site location: $staticSitePath"

    write-host "Spin up jVUNDemo site at $($servedAt)"
    $iisExpressScript = { & 'C:\Program Files (x86)\IIS Express\iisexpress.exe' /path:$jVUNDemo /port:$port } $job = Start-Job -Name RunIisExpress -Scriptblock $iisExpressScript

    write-host "Wait a moment for IIS to startup"
    write-host "$(Get-Date -format 'u') Job state: $($job.state)"
    Wait-Job $job -Timeout 30
    write-host "$(Get-Date -format 'u') Job state: $($job.state)"

    if (Test-Path $staticSitePath) {
    write-host "Removing $($staticSitePath)..." Remove-Item -path $staticSitePath -Recurse -Force }

    Write-Host "Send request to IIS Express..."
    Invoke-RestMethod $servedAt

    write-host "Create static version of demo site here: $($staticSitePath)"
    Push-Location $staticSiteParentPath
    wget.exe --recursive --convert-links -E --directory-prefix=$staticSite --no-host-directories --debug $servedAt
    Pop-Location

    write-host "Shut down jVUNDemo site"
    write-host "$(Get-Date -format 'u') Job state: $($job.state)"
    Stop-Job $job
    do {
    Start-sleep -s 5 } while ($job.state -eq "Running") write-host "$(Get-Date -format 'u') Job state: $($job.state)"
    receive-job $job | out-file jobs.log -append
    cat jobs.log
    Remove-Job $job

    if (Test-Path $staticSitePath) {
    write-host "Contents of $($staticSitePath)" ls $staticSitePath }

    
    
  3. Interestingly I tried chaining on your example code to the end of my PowerShell script as follows:

    #################
    Write-Host "Create default.htm..."
    '<h1>Hello, world!</h1>' | Out-File $buildFolder\default.htm -Encoding UTF8
     
    Write-Host "Start IIS Express..."
    Start-Job -Name RunIisExpress2 -Scriptblock {& 'C:\Program Files (x86)\IIS Express\iisexpress.exe' /path:$buildFolder /port:57614}
    Wait-Job -Name RunIisExpress2 -Timeout 30
     
    Write-Host "Send request to IIS Express..."
    Invoke-RestMethod http://localhost:57614
    #################
    

    This also fails in my build with this message:

    Invoke-RestMethod : Unable to connect to the remote server
    At C:\projects\jquery-validation-unobtrusive-native\makeStatic.ps1:63 char:1
    + Invoke-RestMethod http://localhost:57614
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    

    This makes me think there's some kind of environmental difference between your project and mine. Any thoughts on what it might be? This is my appVeyor.yml:

    #---------------------------------#
    #      general configuration      #
    #---------------------------------#
    
    # version format
    version: 1.0.{build}
    
    #---------------------------------#
    #    environment configuration    #
    #---------------------------------#
    
    # scripts that are called at very beginning, before repo cloning
    init:
      - ps: git config --global user.email "[email blocked]"
      - ps: git config --global user.name "johnnyreilly"
    
    # environment variables
    environment:
      GithubUsername: johnnyreilly
      GithubPassword:
        secure: ilM6UXjXXOmFLz6pDWsoOA==
    
    branches:
      only:
        - master
    
    install:
    - ps: choco install wget
    
    build:
      verbosity: minimal
    
    after_build:
    - ps: git remote -v
    - ps: ./makeStatic.ps1 $env:APPVEYOR_BUILD_FOLDER
    
  4. Completed could be mean the process immediately exited with non-zero code. What could be a problem? I think it could be due to site home folder or already taken port or something else. Try seeing what exit code IIS Express returns ($LastExitCode)

  5. Hi Feodor,

    I got round the issue by switching from jobs to processes in Powershell. Even though it all works as expected AppVeyor is showing the output in the "red angry text of sin". Which is a bit weird. Any idea why? As I see it seems to work fine otherwise...

    Example build here

  6. Hi Johnny,

    Glad it finally works!

    Regarding red - that's an easy one - seems wget.exe writes to STDERR (and it's a usual habit for most unix tools). PowerShell treats anything in STDERR as kind of RemoteException. Try using 2>&1 redirection: http://steve-jansen.github.io/guides/windows-batch-scripting/part-4...

  7. Hi Feodor,

    Boom! It worked!

    My shell knowledge is much weaker than I'd like it to be (something |'m working on). So you've taught me something - thanks!

  8. johnny_reilly closed this discussion on 31 Dec, 2014 11:22 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions