如何在Chocolatey安装脚本中下载基于身份验证的基本文件?

问题描述 投票:1回答:2

在下载文件时,Install-ChocolateyZipPackage命令行开关似乎不支持基本身份验证,即通过https://user:[email protected]/file.zip等URL。我如何在我的Chocolatey安装脚本中解决这个问题,即在我通过Install-ChocolateyZipPackage安装之前下载有问题的文件(例如https://user:[email protected]/file.zip)?

basic-authentication chocolatey
2个回答
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)

0
投票

我使用类似的方法,没有wget,从我们公司的构建服务器获取工件

$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"
© www.soinside.com 2019 - 2024. All rights reserved.