Install-ChocolateyZipPackage命令行开关在下载文件时似乎不支持基本身份验证,即通过https://user:password@example.com/file.zip
等URL。我如何在我的Chocolatey安装脚本中解决这个问题,即在我通过Install-ChocolateyZipPackage安装之前下载有问题的文件(例如https://user:password@example.com/file.zip
)?
答案 0 :(得分:1)
托马斯在小组论坛中提出了一个很好的答案 - https://groups.google.com/forum/#!msg/chocolatey/e4lcPIrLhis/vfSUVe0SZcIJ
据我所知,不支持身份验证。但你可以 将wget指定为依赖项并使用它来下载文件。
我在我的一个软件包中使用它进行身份验证,它运行正常: https://chocolatey.org/packages/rukerneltool#files(看看chocolateyInstall.ps1)
在Linux上,wget将成为处理这类事物的首选 Bash脚本。
但是,如果要制作软件包的软件是开源软件,那么 可以将它直接集成到包中。这样会更容易。
此代码(如果以后更改:
$webClient = New-Object System.Net.WebClient
$webClient.Credentials = New-Object System.Net.Networkcredential($username, $password)
Write-Output $('Downloading' + $url + '…')
$webClient.DownloadFile($url, $zipFilePath)
答案 1 :(得分:0)
我使用类似的方法,没有wget,从我们公司的buildserver
获取工件$packageName = 'mycompanypackage'
$installerType = 'exe'
$username = 'chocolatey'
$password = '************'
$url = 'http://bamboo.mycompany.com/browse/DP-RS/latestSuccessful/artifact/JOB1/Setup/setup.exe'
$downloadFile = $url.Substring($url.LastIndexOf("/") + 1)
$url = $url+'?os_authType=basic'
$url64 = $url
$silentArgs = '/VERYSILENT /NORESTART /SUPPRESSMSGBOXES'
if (Test-Path "$downloadFile") {Remove-Item "$downloadFile"}
$webclient = new-object System.Net.WebClient
$credCache = new-object System.Net.CredentialCache
$creds = new-object System.Net.NetworkCredential($username, $password)
$credCache.Add($url, "Basic", $creds)
$webclient.Credentials = $credCache
$webclient.DownloadFile($url, $downloadFile)
Install-ChocolateyInstallPackage "$packageName" "$installerType" "$silentArgs" "$downloadFile"