2

We are deploying a scheduled web job to Azure. The web job is developed using Visual Studio 2015. The 'settings.job' file contains the schedule definition. However, we want to use a different schedule depending on whether we are deploying to a 'development' environment or a 'staging/production' environment. What is the best way to accomplish this?

This is an update to the above question. The answer below by Sentinel worked when as we where deploying from GitHub. However, now we are using Visual Studio Team Services for builds and deployments into Azure and that method no longer works. It's almost as though VSTS is making copies of the original settings.job file into other locations prior to the pre-build event that copies the per-environment version over the original settings.job and it is using those copies to create the deployment package. Any insight or suggtestion would be appreciated.

melvers
  • 353
  • 2
  • 10

3 Answers3

1

I would write a PowerShell script to achieve this. In build definition create a variable to store the settings.job file location and another variable to store the schedule. Then using PowerShell script utility in VSTS I would update the settings file.

Below code would update the file.

param(
    [Parameter(Mandatory=$true)][string]$configFile, 
    [Parameter(Mandatory=$true)][string]$schedule
)

$j = Get-Content $configFile -Raw | ConvertFrom-Json
$j.schedule = $schedule
$j | ConvertTo-Json | set-content $configFile
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Shridhar
  • 49
  • 7
0

According to your description, I suggest you could use MSbuild to achieve your requirement.

I suggest you firstly generate the publish file by using the publish as webjob tab and add a blank settings.job file in the project root path.

The result is like below:

enter image description here

Then you could define a folder to store the different settings.job files. Notcie: You need to changed the file name as same as the PublishProfiles' name. Like below:

AzureWebTest20170214103506-development - Web Deploy.job enter image description here

At last you could change csproj file using the xcopy to copy the file to the project path.

1.Unload the project

2.Right click the project name ---> Edit project.csproj

enter image description here

3.Change the after target as below:

   <Target Name="AfterBuild">
    <PropertyGroup>
      <test>"$(ProjectDir)sec\$(_PublishProfileName).job"</test>
    </PropertyGroup>
    <Message Text="Test = $(_PublishProfileName)">
    </Message>
    <Exec Command="xcopy.exe  $(test) $(ProjectDir)settings.job /Y" WorkingDirectory="C:\Windows\" />
  </Target>

When you publish the webjob, it will copy the right job.settings according to the 'PublishProfileName.job' content.

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
  • Any update? If you feel my answer is useful /helpful. Please mark it as an answer so that other folks could benefit from it. – Brando Zhang May 03 '17 at 02:08
0

You could just have multiple json files like settings.debug, then use a prebuild event that would use the $(ConfigurationName) macro to copy and overwrite settings.job

Pre-build events can be edited in the project settings.

Sentinel
  • 3,582
  • 1
  • 30
  • 44