1

The CI/CD process:

  1. compiles an executable and uploads it to Azure Storage.
  2. Uploads the "custom script" (that downloads the executable and runs it) to Azure Storage.
  3. Deploys an ARM template of a VM that has a CustomScriptExtension that downloads and runs the custom script.

The subsequent builds update the script and the executable but the VM doesn't pull down the updated script. How to make it redownload and run the script that would run the updated executable?

alvarez
  • 700
  • 7
  • 19

1 Answers1

5

In order for the CustomScriptExtension to be executed on an existing VM, the configuration of that extension must be "different" than the last time it was deployed - if it looks the same, i.e. every property value in the json resource is the same as the last time, the extension is not reapplied.

There are two simple ways you can make the configuration "different".

1) is change any property value in the resource, this might not always be practical (and in some cases the opposite of what you really want to do) so the most reasonable property to change is the fileUris property. Generally this property contains a sasToken, that is generated for that particular deployment. Since the sasToken is different each time the property value changes and the extension is re-applied. You can see a sample of this here:

https://github.com/bmoore-msft/AzureRM-Samples/tree/master/VMCSEInstallFilePS

Look at the scripts in the root, that deploy the template.

2) If #1 doesn't fit the workflow, you can control this a little more by using the forceUpdateTag property on the resource. You "seed" this value with whatever string you want on the first deployment and then change the value on a subsequent deployment to re-apply the extension. So for example, you could use a parameter and increment that value whenever you wanted to force a change.

enter image description here

HTH

bmoore-msft
  • 8,376
  • 20
  • 22
  • Thanks, looks like it indeed works with plain VMs (which answers the question). I also tried with VM scale sets but couldn't get it to work in that case. – alvarez Jun 14 '16 at 10:14
  • Got it working! The upgradePolicy mode in the template was Manual. Setting it to Automatic solves the problem. – alvarez Jun 17 '16 at 07:57
  • @bmoore-msft I am having similar problems and I noticed you removed forceUpdateTag from the sample script you linked to. Does this no longer work? I even tried changing commandToExecute (which from your previous comments seems like I shouldn't need forceUpdateTag at all) and it is still executing the old command. Any ideas? Thanks! – gregjhogan Aug 01 '16 at 04:55
  • You only need the forceUpdateTag if the rest of the properties are static... The sample generates a new sasToken on every deployment so that's enough to trigger the extension to re-run again. If you're not generating a new sasToken (and the rest of the properties are static (which would be normal)) then add the forceUpdateTag back and seed it with a new value every time you want to force execution. – bmoore-msft Aug 03 '16 at 15:42