我在 Jenkins 中运行 Packer,使用 Chocolatey 将软件包安装到 Windows Server 上,然后再将其创建为 AMI,目前我遇到一个问题,packer 中的 chocolatey 未将 -y 传递到“choco install”。Packer 目前停留在“通过安装,您接受软件包的许可证”。
以下是错误消息:
[0;32m amazon-ebs: WinRM connected.[0m
[1;32m==> amazon-ebs: Connected to WinRM![0m
[1;32m==> amazon-ebs: Provisioning with Powershell...[0m
[1;32m==> amazon-ebs: Provisioning with powershell script: /tmp/powershell-provisioner816199866[0m
[0;32m amazon-ebs: Getting latest version of the Chocolatey package for download.[0m
[0;32m amazon-ebs: Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.13.[0m
[0;32m amazon-ebs: Downloading 7-Zip commandline tool prior to extraction.[0m
[0;32m amazon-ebs: Extracting C:\Users\ADMINI~1\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\ADMINI~1\AppData\Local\Temp\chocolatey\chocInstall...[0m
[0;32m amazon-ebs: Installing chocolatey on this machine[0m
[0;32m amazon-ebs: Creating ChocolateyInstall as an environment variable (targeting 'Machine')[0m
[0;32m amazon-ebs: Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'[0m
[0;32m amazon-ebs: WARNING: It's very likely you will need to close and reopen your shell[0m
[0;32m amazon-ebs: before you can use choco.[0m
[0;32m amazon-ebs: Restricting write permissions to Administrators[0m
[0;32m amazon-ebs: We are setting up the Chocolatey package repository.[0m
[0;32m amazon-ebs: The packages themselves go to 'C:\ProgramData\chocolatey\lib'[0m
[0;32m amazon-ebs: (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).[0m
[0;32m amazon-ebs: A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'[0m
[0;32m amazon-ebs: and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.[0m
[0;32m amazon-ebs: Creating Chocolatey folders if they do not already exist.[0m
[0;32m amazon-ebs: WARNING: You can safely ignore errors related to missing log files when[0m
[0;32m amazon-ebs: upgrading from a version of Chocolatey less than 0.9.9.[0m
[0;32m amazon-ebs: 'Batch file could not be found' is also safe to ignore.[0m
[0;32m amazon-ebs: 'The system cannot find the file specified' - also safe.[0m
[0;32m amazon-ebs: chocolatey.nupkg file not installed in lib.[0m
[0;32m amazon-ebs: Attempting to locate it from bootstrapper.[0m
[0;32m amazon-ebs: PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...[0m
[0;32m amazon-ebs: WARNING: Not setting tab completion: Profile file does not exist at[0m
[0;32m amazon-ebs: 'C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profil[0m
[0;32m amazon-ebs: e.ps1'.[0m
[0;32m amazon-ebs: Chocolatey (choco.exe) is now ready.[0m
[1;32m==> amazon-ebs: Provisioning with Powershell...[0m
[1;32m==> amazon-ebs: Provisioning with powershell script: /tmp/powershell-provisioner259657802[0m
[0;32m amazon-ebs: Chocolatey v0.10.13[0m
[0;32m amazon-ebs: Installing the following packages:[0m
[0;32m amazon-ebs: notepadplusplus[0m
[0;32m amazon-ebs: By installing you accept licenses for the packages.[0m
以下是 Packer JSON 文件
{
"provisioners": [
{
"type": "powershell",
"inline": [
"iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"
]
},
{
"type": "powershell",
"inline": [
"choco install -y notepadplusplus",
"choco install -y googlechrome",
"choco install -y firefox"
]
},
{
"type": "powershell",
"inline": [
"C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SendWindowsIsReady.ps1 -Schedule",
"C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeInstance.ps1 -Schedule",
"C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SysprepInstance.ps1 -NoShutdown"
]
}
],
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "Windows_Server-2012-R2_RTM-English-64Bit-Base-*",
"root-device-type": "ebs"
},
"owners": ["amazon"],
"most_recent": true
},
"instance_type": "t2.micro",
"winrm_username": "Administrator",
"ami_name": "Windows_2012_base-{{timestamp}}",
"user_data_file": "SetUpWinRM.ps1",
"communicator": "winrm",
"winrm_use_ssl": true,
"winrm_insecure": true,
"launch_block_device_mappings": [{
"device_name": "/dev/sda1",
"volume_size": 60,
"volume_type": "gp2",
"delete_on_termination": true
}]
}]
}
答案1
我遇到了完全相同的问题 - 在打包脚本中调用“choco install XXX”卡在“通过安装,您接受软件包的许可证”行。
解决方案是使用旧版打包程序 1.3.1。目前最新的 1.4.0 不适用于此。
希望能帮助到你。