Search code examples
c#continuous-integration.net-corewebjob

Build definition for NETCore2 WebJob in VSTS


I am setting up a build definition in Visual Studio Team Services for a WebApp including some WebJobs, all of which are in .NET Core 2. The tasks that are setup are:

  • NuGet 4.4.1: NuGet tool installer
  • NuGet restore
  • NPM Install
  • Gulp
  • Build solution (containing all projects in the .sln, including the webapp and the webjob).
  • Azure App Service Deploy: (webapp)
  • Azure App Service Deploy: (webjob)
  • Update Database (.dacpac)
  • rest/cleanup...

Problem 1: with .NETCore 2 i am unable to link the webjob to the webapp in VS2017.

Problem 2: I cannot seem to find a way to deploy the webjob to the subfolder /site/wwwroot/app_data/Jobs/Triggered in the webapp destination. For this i tried setting arguments on msdeploy (like -dest:), but failed as well.

Problem 3: there doesn't seem to be any task specifically for this in the marketplace.

Problem 4: (Not a real problem, but ok), I am unable to find any hints browsing thru the web.

The msbuild argumentsin the Build task:

/m /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"

So i then have several zipped project, which i can then pick-up seperately using different Azure App Service Deploy tasks. Everything runs with success, but the webjob isn't published since i seem to be unable to target it to the webapp.

Below is the Azure App Service Deploy output:

>     ##[section]Starting: Azure App Service Deploy: ******devapi webjob
> ============================================================================== Task         : Azure App Service Deploy Description  : Update Azure
> App Service using Web Deploy / Kudu REST APIs Version      : 2.1.14
> Author       : Microsoft Corporation Help         : [More
> Information](https://aka.ms/azurermwebdeployreadme)
> ============================================================================== 9eda6c4a-a587-4dda-b343-fecd5027a2f8 exists true Got connection
> details for Azure App Service:'******devapi' [command]"C:\Program
> Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:getParameters
> -source:package='D:\a\1\a\******.Webjob.zip' <output>   <parameters>
>     <parameter name="IIS Web Application Name" value="Default Web Site" tags="IisApp">
>       <parameterEntry kind="ProviderPath" scope="IisApp" match="^D:\\a\\1\\s\\src\\jobs\\******\.Webjob\\obj\\Release\\netcoreapp2\.0\\PubTmp\\Out\\$"
> />
>     </parameter>   </parameters> [command]"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync
> -source:package='D:\a\1\a\******.Webjob.zip' -dest:auto,ComputerName='https://******devapi.scm.azurewebsites.net:443/msdeploy.axd?site=******devapi',UserName='********',Password='********',AuthType='Basic' -setParam:name='IIS Web Application Name',value='******devapi' -enableRule:AppOffline -enableRule:DoNotDeleteRule -userAgent:VSTS_someguid Info: Using ID 'xxx' for connections to the remote server. Total changes: 0 (0 added, 0 deleted, 0 updated, 0
> parameters changed, 0 bytes copied) App Service successfully deployed
> at url http://******devapi.azurewebsites.net Successfully updated
> deployment History at
> https://******devapi.scm.azurewebsites.net/deployments/27891522952986583
> ##[section]Finishing: Azure App Service Deploy: ******devapi webjob

Please, does someone have any idea on how to deal with WebJobs and build definitions in VSTS?

Edit: I have split the Build and Release, so that the artifact are picked up on a Release Definition after successful build.


Solution

  • So i found my answer following this guide.

    What it does is solve my first problem (which also makes most sense).

    Problem 1: with .NETCore 2 i am unable to link the webjob to the webapp in VS2017.

    This way the webjob is 'hooked' the the application in which you want to publish it. A note for the instruction in this guide. In the webapp .csproj replace/remove $(ProjectDir)$(PublishDir) and set it to your needs.

    <Target Name="PostpublishScript" AfterTargets="Publish">  
        <Exec Command="dotnet publish ..\Azure.WebJob.Continous\ -o $(ProjectDir)$(PublishDir)App_Data\Jobs\Continuous\Azure.WebJob.Continous" />
        <Exec Command="dotnet publish ..\Azure.WebJob.Triggered\ -o $(ProjectDir)$(PublishDir)App_Data\Jobs\Triggered\Azure.WebJob.Triggered" />
    </Target>