Deploy nodejs webjobs to Azure App Service with VSTS

During 2 years, we were gently deploying nodejs & dotnet webjobs with VSTS & a private agent/pipeline with ... FTP method (not ftps). Wasn't best practise, wasn't really secure, but worked for 2 years.

We had to move our private agent/pipeline to another datacenter and suddenly, network rules were more stricts: neither ftp nor ftps, only sftp. unfortunately, Azure doesn't support sftp.

ok you win

Let's re-define our build & release pipeline on all our webjobs.
That was easy for dotnet webjobs by including Microsoft.Web.WebJobs.Publish nuget and configuring webjob-publish-settings.json: official documentation is full & complete.

However, for nodejs webjobs, official documentation was empty, google returned nothing: like nobody has done this before. Finally found this non-answered (at the time) thread on Stackoverflow and decided to address it.

# Build

A working approach is creating a zip archive with webjob structure relative to D:\home\site\wwwroot during the build pipeline.

unfortunately, Archive task (2.*) isn't supporting output folder within the archive, we have to recreate the structure before: inline powershell will do the job.

  1. move webjob structure into valid production one with powershell
  2. npm install pointing to correct working folder, preventing moving all node_modules with previous task
  3. archive
  4. publish
Remove-Item -Path $(Build.BinariesDirectory)\app_data -Force -Confirm:$false -Recurse -ErrorAction:Ignore  
New-Item $(Build.BinariesDirectory)\app_data\jobs\continuous\ -ItemType Directory -Force  
Move-Item $(Build.SourcesDirectory)\webjobA\ $(Build.BinariesDirectory)\app_data\jobs\continuous\webjobA -Force  

inline powershell for a continuous job called webjobA

Remove-Item ensures no previous build leftovers. New-Item creates destination folder & Move-Item push webjobA onto correct location. I do suspect a more generic writing could be done.

# Release

Using an Azure App Service Deploy task with App type Web App and previously generated archive will then deploy it as regular webjob.

Fabien Camous

Read more posts by this author.