##########gitlab output################# $ packer version Packer v1.7.0 $ echo "packer installed now running the image build" packer installed now running the image build $ packer build -var="vcpasswd=$password" -var-file="variables.json" Win2019img.json vsphere-clone: output will be in this color. ==> vsphere-clone: Cloning VM... ==> vsphere-clone: Mounting ISO images... ==> vsphere-clone: Adding configuration parameters... ==> vsphere-clone: Power on VM... ==> vsphere-clone: Waiting for IP... ==> vsphere-clone: IP address: 192.168.168.10 ==> vsphere-clone: Using winrm communicator to connect: Win2k19tp-pack ==> vsphere-clone: Waiting for WinRM to become available... ==> vsphere-clone: Timeout waiting for WinRM. ==> vsphere-clone: Power off VM... ==> vsphere-clone: Destroying VM... ##########Gitlab runner config.toml##################### [[runners]] name = "****" url = "****" token = "****" executor = "docker" [runners.custom_build_dir] [runners.cache] [runners.cache.s3] [runners.cache.gcs] [runners.cache.azure] [runners.docker] tls_verify = false image = "centos:latest" privileged = false disable_entrypoint_overwrite = false oom_kill_disable = false disable_cache = false volumes = ["/cache"] shm_size = 0 network_mode = "host" #########Packer JSON file############################### { "variables": { "vcenter":"", "vcusern":"", "vcpasswd":"", "winrm_username": "administrator", "winrm_password": "***********", "winrm_host": "Win2k19tp-pack" }, "builders": [ { "type": "vsphere-clone", "vcenter_server": "{{user `vcenter`}}", "username": "{{user `vcusern`}}", "password": "{{user `vcpasswd`}}", "insecure_connection": "true", "template": "Win2k19tp-pack", "vm_name": "Win2k19tpl-{{timestamp}}", "cluster": "Cluster", "datastore": "NFS_SAS", "folder": "Templates", "network": "vlan1234", "communicator": "winrm", "winrm_use_ssl": false, "winrm_insecure": true, "winrm_timeout": "5m", "winrm_username": "{{user `winrm_username`}}", "winrm_password": "{{user `winrm_password`}}", "winrm_host": "{{user `winrm_host`}}", "winrm_port":"5985" } ], "provisioners": [ { "type": "file", "source": "./CopyAZPush.ps1", "destination":"c:\\copyAzPsh.ps1" }, { "type": "powershell", "inline": [ "start-process -filepath \"powershell.exe\" -Arg \"c:\\copyAzPsh.ps1\" -Wait -Verb runas" , "invoke-command -scriptblock{write-host \"Copied from storage account, find the following list of downloaded files\" }", "get-childitem C:\\install | write-host" ] }, { "type": "powershell", "elevated_user": "{{user `winrm_username`}}", "elevated_password": "{{user `winrm_password`}}", "scripts": [ "./installscript.ps1" ] }, { "type": "windows-restart", "restart_check_command": "powershell -command \"& {Write-Output 'Machine restarted.'}\"" }, { "type": "powershell", "inline": [ "write-host \"sysprepping the machine \"", "& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit", "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }" ] } ] }