-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ImageFactory scripts - dont create custom image in the factory lab #255
Conversation
…lden image. Instead, the MakeVM scripts will apply the sysprep or deprovision artifact to the created VM and the save/distribute steps will use the sysprepped VM vhds
Just my two cents: I would prefer the sysprep action to be seperate from the MakeVm step. I have some custom uses for the ImageFactory and would prefer this to be in the "SnapImages" step. I understand that this might not fit with everyone else, but wanted to mention it anyway. I also assume you will get this same issue: #251 |
Thanks for the feedback @gregpakes |
@workleodig Understood. The reason I like it separate is because under some scenarios I want to leave the VMs running and not image/distribute them. I guess the PR works for me too as I can use the config options. |
Can I also ask why you have changed the API versions? |
|
||
#add the Sysprep or deprovision artifact to the list of artifacts for the VM | ||
$newArtifact = @{} | ||
if ($armTemplate.resources[0].properties.galleryImageReference.osType -eq 'Windows') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$armTemplate.resources[0].properties.galleryImageReference.osType
is not guaranteed to be in the Arm Template.
Many of my templates are built from custom images, not from gallery references.
Rather than dynamically amending the template, could we:
- Create the VM normally
- Apply the artifact after VM is created - the OS of the VM would be available
Write-Output "Switching to subscription $subId" | ||
Select-AzureRmSubscription -SubscriptionId $subId | Out-Null | ||
Set-AzureRmContext -SubscriptionId $subId | Out-Null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is affected by this bug: Azure/azure-powershell#3954
A workaround is to remove the subscription check in SelectSubscription.
Having ported all my code, I now find out that this is not compatible with VSTS Release Management. It seems it runs an older version of AzureRM, giving the following error:
|
Having ported my own lab to use this - having the sysprep tagged onto the VM creation would be a dealbreaker for me. We use this in VSTS and we interact (install our software) with the VM through the Release Management pipeline as artifacts were not suitable. So this no longer works as the VM is immediately sysprepped and shut down. |
You can disable the sysprep by calling the MakeGoldenImageVMs script with -includeSysprep $false. That will bypass the code that adds the sysprep artifact. You would then need a snippet of code to apply the SysPrep artifact after the fact. I can help track that down if you want. I updated the API versions because I wanted to use the official RTM versions instead of the preview api version. The Set-AzureRmContext issue happens when you run on a machine with an older version of the Azure Powershell cmdlets. We need the newer version of the cmdlets in order to access the Grant-AzureRmDiskAccess cmdlet. We could check the azureRm version in the script and log a more meaningful error, but we will need the newer version installed. |
I am writing this now in my custom factory. I'll PR it if I get it to work.
OK
This is a difficult one. I am using TFS 2017 Update 2 (preview). I don't think I have control to update the cmdlets in the "Azure Powershell" task. Using the Azure Powershell task was one of the main use cases for this image factory originally, so this is probably a blocker for others too. |
I've tried to do this myself, but can't find anything! |
Here's a snippet to apply an artifact to a lab VM
|
@workleodig Thanks for this. This mostly works, but when i try to apply the sysprep artifact, I get this error: Multiple VMExtensions per handler not supported for OS type 'Windows'. VMExtension 'customScriptArtifact-183362431' with handler 'Microsoft.Compute.CustomScriptExtension' already added or specified in input. I am not sure what i can do to get around this. |
@gregpakes, the problem is that the CSE, for some reason, was not deleted from the VM. So, to get around it, you need to go to the corresponding resource group, look at the Extensions blade, and remove the CSE instance giving you problems. Then you can try applying the sysprep artifact again. |
Thanks - I realise this. The issue is that I m doing this as a part of an automation pipeline, so there is no room for manual steps. The whole process needs to be automated. |
Update ImageFactory scripts to avoid using the vhd location of the golden image in the factory lab
Instead, the MakeVM scripts will apply the sysprep or deprovision artifact to the created VM and the save/distribute steps will use the sysprepped VM vhds