This article assumes that we are using TFS 2017 RTM or lower version. In higher versions, we can directly tokenize and deploy the web job using inbuilt task.
Web Job deployment is not as straightforward as App Service deployment or Service Fabric. This is because there is no out of box deployment available task available in Release Management. So, below are the steps you need to take to do end to end deployment.
STEP 1 Creation of Packages using Build Definition
Package creation using BuildDefinition is the first step in the process to deploy web job. Below Screenshot describes the build definition step. The thing to note here is "MSBuild Arguments", which is responsible for the creation of packages.
Value for Build Definition should be,
"/p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageLocation=$(build.artifactstagingdirectory)\WebJob
/p:OutputPath="$(Build.BinariesDirectory)\$(BuildConfiguration)\WebJob/"
Once the package is created using above step, you can save the artifacts to the server using "Copy and Publish Artifacts" task to be available in Release Definition.
STEP 2 Deploy using Release Definition
Once the package is available in Release Definition, there are two steps involved to deploy a web job,
- Tokenize the Web Job
- Deploy the Web Job
Let's see them one by one below,
Tokenize the Web Job
Tokenization of web job is nothing but to change the AppSetting values with the environment specific values. To do so, you can use Replace token task to do so. Below is the screenshot of it. This will take the source path you have the zipped folder and then use Regex operation, will search and replace your token values.(Note: Make sure you unzip the package folder and provide to this task to do tokenization. After tokenization again zip it and do a web deploy)
Deploy the Web Job
Once tokenization is complete, deployment of Web Job can be done using task "Azure RM Web App Deployment". In this step, you can give the package folder path, which was tokenized in step above. Also, notice that web job is deployed under an App Service, so you need to provide the web app name under which you want to deploy your web job.
Once all above step executes successfully, you can see the deployed web job in portal under the Web App.
To check tokenized values, you need to browse through kudu service and check the deployed web job config (Since its a web job, the config will be in the type "webjobname.exe.config".