diff --git a/images.CI/linux-and-win/download-repo.ps1 b/images.CI/download-repo.ps1 similarity index 100% rename from images.CI/linux-and-win/download-repo.ps1 rename to images.CI/download-repo.ps1 diff --git a/images.CI/linux-and-win/azure-pipelines/image-generation.yml b/images.CI/linux-and-win/azure-pipelines/image-generation.yml index 30499ce3f..38aabd142 100644 --- a/images.CI/linux-and-win/azure-pipelines/image-generation.yml +++ b/images.CI/linux-and-win/azure-pipelines/image-generation.yml @@ -26,7 +26,7 @@ jobs: displayName: 'Build VM' inputs: targetType: filePath - filePath: ./images.CI/build-image.ps1 + filePath: ./images.CI/linux-and-win/build-image.ps1 arguments: -ResourcesNamePrefix $(Build.BuildId) ` -ClientId $(CLIENT_ID) ` -ClientSecret $(CLIENT_SECRET) ` @@ -45,7 +45,7 @@ jobs: displayName: 'Create release for VM deployment' inputs: targetType: filePath - filePath: ./images.CI/create-release.ps1 + filePath: ./images.CI/linux-and-win/create-release.ps1 arguments: -BuildId $(Build.BuildId) ` -Organization $(RELEASE_TARGET_ORGANIZATION) ` -DefinitionId $(RELEASE_TARGET_DEFINITION_ID) ` @@ -66,7 +66,7 @@ jobs: condition: always() inputs: targetType: filePath - filePath: ./images.CI/cleanup.ps1 + filePath: ./images.CI/linux-and-win/cleanup.ps1 arguments: -ResourcesNamePrefix $(Build.BuildId) ` -ClientId $(CLIENT_ID) ` -ClientSecret $(CLIENT_SECRET) ` diff --git a/images.CI/macos/azure-pipelines/image-generation.yml b/images.CI/macos/azure-pipelines/image-generation.yml index 40cf4d43a..df1c056e2 100644 --- a/images.CI/macos/azure-pipelines/image-generation.yml +++ b/images.CI/macos/azure-pipelines/image-generation.yml @@ -28,30 +28,30 @@ jobs: SourceFolder: 'images/macos/provision/log/' RemoveSourceFolder: true - - bash: | - export PACKER_LOG=0 - 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=${{ parameters.target_datastore }}" \ - -var="output_folder=mms-output" \ - -var="vm_username=$(vm_username)" \ - -var="vm_password=$(vm_password)" \ - -var="build_id=$(Build.BuildNumber)" \ - -var="baseimage_name=${{ parameters.base_image_name }}" \ - -var="azure_storage_sas=$(AZURE_STORAGE_SAS)" \ - -var="azure_storage_account=$(AZURE_STORAGE_ACCOUNT)" \ - -var="build_assets_url=$(appcenter_build_assets_url)" \ - -var="github_feed_token=$(GITHUB_FEED_TOKEN)" \ - -var="xcode_install_user=$(xcode-installation-user)" \ - -var="xcode_install_password=$(xcode-installation-password)" \ - -color=false \ - ${{ parameters.template_path }} + - task: PowerShell@2 + displayName: 'Build VM' + inputs: + targetType: filePath + filePath: ./images.CI/macos/build-image.ps1 + arguments: -Image "${{ parameters.image_name }}" ` + -VcenterServer "$(vcenter_server_v2)" ` + -VcenterUsername "$(vcenter_username_v2)" ` + -VcenterPassword "$(vcenter_password_v2)" ` + -VcenterDatacenter "$(vcenter_datacenter_v2)" ` + -EsxiCluster "$(esxi_cluster_v2)" ` + -TargetDatastore "${{ parameters.target_datastore }}" ` + -OutputFolder "mms-output" ` + -VmUsername "$(vm_username)" ` + -VmPassword "$(vm_password)" ` + -BuildId "$(Build.BuildNumber)" ` + -BaseImageName "${{ parameters.base_image_name }}" ` + -AzureStorageSas "$(AZURE_STORAGE_SAS)" ` + -AzureStorageAccount "$(AZURE_STORAGE_ACCOUNT)" ` + -BuildAssetsUrl "$(appcenter_build_assets_url)" ` + -GithubFeedToken "$(GITHUB_FEED_TOKEN)" ` + -XcodeInstallationUser "$(xcode-installation-user)" ` + -XcodeInstallationPassword "$(xcode-installation-password)" workingDirectory: 'images/macos' - displayName: Build image - bash: | echo "Copy image output files" @@ -82,3 +82,11 @@ jobs: failTaskOnFailedTests: true displayName: Publish test results condition: always() + + - task: Bash@3 + inputs: + targetType: filePath + filePath: ./images.CI/macos/destroy_vm.sh + arguments: '"$(vcenter_server_v2)" "$(vcenter_username_v2)" "$(vcenter_password_v2)" "$(vcenter_datacenter_v2)/vm/mms-output/$(Build.BuildNumber)"' + condition: eq(variables['Agent.JobStatus'], 'Canceled') + displayName: Destroy VM (if build canceled only) \ No newline at end of file diff --git a/images.CI/macos/azure-pipelines/macos1013.yml b/images.CI/macos/azure-pipelines/macos1013.yml index 04a76346d..2dfeffdeb 100644 --- a/images.CI/macos/azure-pipelines/macos1013.yml +++ b/images.CI/macos/azure-pipelines/macos1013.yml @@ -18,6 +18,5 @@ jobs: parameters: image_label: 'macOS High Sierra' base_image_name: 'clean-macOS-10.13.6-380Gb-SIPoff_runner' - template_path: 'templates/macOS-10.13.json' + image_name: 'macOS-10.13' target_datastore: 'ds-image' - stable: false diff --git a/images.CI/macos/azure-pipelines/macos1014.yml b/images.CI/macos/azure-pipelines/macos1014.yml index 8149c55c2..521f7abf9 100644 --- a/images.CI/macos/azure-pipelines/macos1014.yml +++ b/images.CI/macos/azure-pipelines/macos1014.yml @@ -18,6 +18,5 @@ jobs: parameters: image_label: 'macOS Mojave' base_image_name: 'clean-macOS-10.14-380Gb_runner' - template_path: 'templates/macOS-10.14.json' + image_name: 'macOS-10.14' target_datastore: 'ds-image' - stable: false diff --git a/images.CI/macos/azure-pipelines/macos1015.yml b/images.CI/macos/azure-pipelines/macos1015.yml index 7fc37016a..eea21f4ea 100644 --- a/images.CI/macos/azure-pipelines/macos1015.yml +++ b/images.CI/macos/azure-pipelines/macos1015.yml @@ -18,6 +18,5 @@ jobs: parameters: image_label: 'macOS Catalina' base_image_name: 'clean-macOS-10.15-380Gb-runner' - template_path: 'templates/macOS-10.15.json' + image_name: 'macOS-10.15' target_datastore: 'ds-image' - stable: false diff --git a/images.CI/macos/build-image.ps1 b/images.CI/macos/build-image.ps1 new file mode 100644 index 000000000..eae76eebe --- /dev/null +++ b/images.CI/macos/build-image.ps1 @@ -0,0 +1,55 @@ +param( + [String] [Parameter (Mandatory=$true)] $Image, + [String] [Parameter (Mandatory=$true)] $VcenterServer, + [String] [Parameter (Mandatory=$true)] $VcenterUsername, + [String] [Parameter (Mandatory=$true)] $VcenterPassword, + [String] [Parameter (Mandatory=$true)] $VcenterDatacenter, + [String] [Parameter (Mandatory=$true)] $EsxiCluster, + [String] [Parameter (Mandatory=$true)] $TargetDatastore, + [String] [Parameter (Mandatory=$true)] $OutputFolder, + [String] [Parameter (Mandatory=$true)] $VmUsername, + [String] [Parameter (Mandatory=$true)] $VmPassword, + [String] [Parameter (Mandatory=$true)] $BuildId, + [String] [Parameter (Mandatory=$true)] $BaseImageName, + [String] [Parameter (Mandatory=$true)] $AzureStorageSas, + [String] [Parameter (Mandatory=$true)] $AzureStorageAccount, + [String] [Parameter (Mandatory=$true)] $BuildAssetsUrl, + [String] [Parameter (Mandatory=$true)] $GithubFeedToken, + [String] [Parameter (Mandatory=$true)] $XcodeInstallationUser, + [String] [Parameter (Mandatory=$true)] $XcodeInstallationPassword +) + +$TemplatePath = (Get-ChildItem -Path "images" -Include "$Image.json" -Recurse -Depth 2).FullName +if (-not $TemplatePath) +{ + Write-Error "'-Image' parameter is not valid. You have to specify correct image type." + exit 1 +} + +$env:PACKER_LOG = 0 + +packer validate -syntax-only $TemplatePath + +Write-Host "Show Packer Version" +packer --version + +Write-Host "Build $Image VM" +packer build -on-error=abort -var="vcenter_server=$VcenterServer" ` + -var="vcenter_username=$VcenterUsername" ` + -var="vcenter_password=$VcenterPassword" ` + -var="vcenter_datacenter=$VcenterDatacenter" ` + -var="cluster_or_esxi_host=$EsxiCluster" ` + -var="esxi_datastore=$TargetDatastore" ` + -var="output_folder=$OutputFolder" ` + -var="vm_username=$VmUsername" ` + -var="vm_password=$VmPassword" ` + -var="build_id=$BuildId" ` + -var="baseimage_name=$BaseImageName" ` + -var="azure_storage_sas=$AzureStorageSas" ` + -var="azure_storage_account=$AzureStorageAccount" ` + -var="build_assets_url=$BuildAssetsUrl" ` + -var="github_feed_token=$GithubFeedToken" ` + -var="xcode_install_user=$XcodeInstallationUser" ` + -var="xcode_install_password=$XcodeInstallationPassword" ` + -color=false ` + $TemplatePath \ No newline at end of file diff --git a/images.CI/macos/destroy_vm.sh b/images.CI/macos/destroy_vm.sh new file mode 100644 index 000000000..cd7863cda --- /dev/null +++ b/images.CI/macos/destroy_vm.sh @@ -0,0 +1,18 @@ +VCENTER_SERVER=$1 +VCENTER_USERNAME=$2 +VCENTER_PASSWORD=$3 +VM_IPATH=$4 + +URLENCODE="image-generation/bootstrap/support/urlencode.sh" + +govc vm.power -k=true \ +-off=true \ +-u "$VCENTER_USERNAME:`$URLENCODE "$VCENTER_PASSWORD"`@$VCENTER_SERVER" \ +-vm.ipath="$VM_IPATH" + +#Time to VM's shutdown +sleep 30 + +govc vm.destroy -k=true \ +-u "$VCENTER_USERNAME:`$URLENCODE "$VCENTER_PASSWORD"`@$VCENTER_SERVER" \ +-vm.ipath="$VM_IPATH" \ No newline at end of file