Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

azure - How to force VM created with an ARM template + CustomScriptExtension to redownload the script and run it?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...