Files
runner-images/images.CI/macos/azure-pipelines/image-generation.yml
Shamil Mubarakshin 4960fde8f7 [macos] Convert packer templates to HCL2 (#9098)
* [macos] Convert packer templates to HCL2

* Fix inline shell provisioner

* Fix folder name

* Fix bootstrap folder copy
2024-01-05 12:29:46 +01:00

150 lines
5.6 KiB
YAML

jobs:
- job: Image_generation
displayName: Image Generation (${{ parameters.image_label }})
timeoutInMinutes: 1200
pool:
name: Mac-Cloud Image Generation
variables:
- group: Mac-Cloud Image Generation
steps:
- pwsh: |
$cleanBuildNumber = "$(Build.BuildNumber)" -replace "(.+_unstable)(\.\d+)", '$1'
$virtualMachineName = "${cleanBuildNumber}.$(System.JobAttempt)"
echo "##vso[task.setvariable variable=VirtualMachineName;]$virtualMachineName"
echo "##vso[build.updatebuildnumber]$virtualMachineName"
displayName: Update BuildNumber
- checkout: self
clean: true
fetchDepth: 1
- task: PowerShell@2
displayName: 'Validate contributor permissions'
condition: startsWith(variables['Build.SourceBranch'], 'refs/pull/')
inputs:
targetType: 'filePath'
filePath: ./images.CI/macos/validate-contributor.ps1
pwsh: true
arguments: -RepositoryName "$(Build.Repository.Name)" `
-AccessToken "$(github-feed-token)" `
-SourceBranch "$(Build.SourceBranch)" `
-ContributorAllowList "$(CONTRIBUTOR_ALLOWLIST)"
- task: PowerShell@2
displayName: 'Download custom repository'
condition: and(ne(variables['CUSTOM_REPOSITORY_URL'], ''), ne(variables['CUSTOM_REPOSITORY_BRANCH'], ''))
inputs:
targetType: 'filePath'
filePath: ./images.CI/download-repo.ps1
arguments: -RepoUrl $(CUSTOM_REPOSITORY_URL) `
-RepoBranch $(CUSTOM_REPOSITORY_BRANCH)
- task: DeleteFiles@1
displayName: Clean up self-hosted machine
inputs:
SourceFolder: 'images/macos/provision/log/'
RemoveSourceFolder: true
- task: PowerShell@2
displayName: 'Select datastore'
inputs:
targetType: 'filePath'
filePath: ./images.CI/macos/select-datastore.ps1
arguments: -VMName "$(VirtualMachineName)" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword '$(vcenter-password-v2)' `
-Cluster "$(esxi-cluster-v2)"
- pwsh: |
$SensitiveData = @(
'IP address:',
'Using ssh communicator to connect:'
)
packer init ${{ parameters.template_path }}
packer build -on-error=abort `
-var="vcenter_server=$(vcenter-server-v2)" `
-var="vcenter_username=$(vcenter-username-v2)" `
-var='vcenter_password=$(vcenter-password-v2)' `
-var="vcenter_datacenter=$(vcenter-datacenter-v2)" `
-var="cluster_or_esxi_host=$(esxi-cluster-v2)" `
-var="esxi_datastore=$(buildDatastore)" `
-var="output_folder=$(output-folder)" `
-var="vm_username=$(vm-username)" `
-var="vm_password=$(vm-password)" `
-var="github_api_pat=$(github_api_pat)" `
-var="build_id=$(VirtualMachineName)" `
-var="baseimage_name=${{ parameters.base_image_name }}" `
-var="xcode_install_storage_url=$(xcode_install_storage_url)" `
-var="xcode_install_sas=$(xcode_install_sas)" `
-color=false `
${{ parameters.template_path }} `
| Where-Object {
#Filter sensitive data from Packer logs
$currentString = $_
$sensitiveString = $SensitiveData | Where-Object { $currentString -match $_ }
$sensitiveString -eq $null
}
displayName: 'Build VM'
workingDirectory: 'images/macos'
env:
PACKER_LOG: 1
PACKER_LOG_PATH: $(Agent.TempDirectory)/packer-log.txt
- bash: |
echo "Copy software report files"
cp -vR "images/image-output/software-report/." "$(Build.ArtifactStagingDirectory)/"
echo "Put VM name to 'VM_Done_Name' file"
echo "$(VirtualMachineName)" > "$(Build.ArtifactStagingDirectory)/VM_Done_Name"
displayName: Prepare artifact
- bash: |
cat "$(Build.ArtifactStagingDirectory)/systeminfo.md"
displayName: Print markdown software report
- bash: |
cat "$(Build.ArtifactStagingDirectory)/systeminfo.json"
displayName: Print json software report
- task: PublishBuildArtifacts@1
inputs:
ArtifactName: 'Built_VM_Artifacts'
displayName: Publish Artifacts
- task: PowerShell@2
displayName: 'Print provisioners duration'
inputs:
targetType: 'filePath'
filePath: ./images.CI/measure-provisioners-duration.ps1
arguments: -PackerLogPath "$(Agent.TempDirectory)/packer-log.txt" `
-PrintTopNLongest 25
- task: PowerShell@2
displayName: 'Move vm to cold storage and clear datastore tag'
condition: always()
inputs:
targetType: 'filePath'
filePath: ./images.CI/macos/move-vm.ps1
arguments: -VMName "$(VirtualMachineName)" `
-TargetDataStore "${{ parameters.target_datastore }}" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword '$(vcenter-password-v2)' `
-CpuCount "$(cpu-count)" `
-CoresPerSocketCount "$(cores-per-socket-count)" `
-Memory "$(memory)"
- task: PowerShell@2
displayName: 'Destroy VM (if build canceled only)'
condition: eq(variables['Agent.JobStatus'], 'Canceled')
inputs:
targetType: 'filePath'
filePath: ./images.CI/macos/destroy-vm.ps1
arguments: -VMName "$(VirtualMachineName)" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword '$(vcenter-password-v2)'