Continuous Deployment of Web Jobs with Node.js on Azure
Recently I was required to build a pipeline with Node.js and deploy it to Azure Cloud.
I decided to use Web Jobs (a feature of Azure App Services) to be the container of the code running the Node.js applications of each role in the pipeline.
The main problem with this approach was that although Azure App Services offers the ability to connect to a GitHub repository using Continuous Deployment it seems that you can only create Web Apps using Node.js.
Digging a little into the structure of Web Apps and Web Jobs I was able to discern that when you create the right folder structure Azure App Services recognizes the web job and displays it appropriately in the Azure Portal.
Creating a Web Job
This is the process used:
- Under package.json I add the following section:
"postinstall": "node ensure-folder-hierarchy.js"
This will call a method that creates the right folder structure after npm install.
2. ensure-folder-hierarchy.js should look something like this:
This will ensure the following folder structure:
Or, in the case of a triggered worker:
This will ensure your continuous or triggered Web Job will be created appropriately.
Note 1: The triggered Web Job will not appear as Scheduled in the portal but as Triggered, but will still be triggered according to the CRON expression you provided.
Note 2: If you want to create a manual triggered Web Job simply create a triggered Web Job but don’t supply a settings.job file.