我们开始使用Azure DevOps构建和部署我的应用程序。目前,我们不将应用程序图像上传到我们的仓库中。我想知道是否可以将所有图像下载到将在构建管道中生成的工件中。
我的yml管道: 触发: -开发
池: vmImage:“ windows最新”
变量: 解决方案:“ ** / *。sln” buildPlatform:“任何CPU” buildConfiguration:“发布”
步骤: -任务:NuGetToolInstaller @ 0
任务:NuGetCommand @ 2 输入: restoreSolution:'$(解决方案)'
任务:Npm @ 1 输入: 命令:“安装” workingDir:“ applicationFolder / app”
任务:VSBuild @ 1 输入: 解决方案:“ $(solution)” msbuildArgs:'/ p:DeployOnBuild = true / p:WebPublishMethod = Package / p:PackageAsSingleFile = true / p:SkipInvalidConfigurations = true /p:PackageLocation="$(build.artifactStagingDirectory)“' 平台:“ $(buildPlatform)” 配置:'$(buildConfiguration)'
任务:PublishBuildArtifacts @ 1 输入: 发布路径:“ $(Build.ArtifactStagingDirectory)” ArtifactName:“ drop” publishLocation:“容器”
答案 0 :(得分:0)
是否可以在Azure DevOps上的构建管道中下载文件?
简短的答案是肯定的。
没有开箱即用的任务可以从FTP服务器下载文件。只有FTP Upload task不能将文件上传到FTP服务器。
因此,要解决此问题,我们可以使用powershell脚本连接到FTP服务器并下载文件:
类似的脚本:
#FTP Server Information - SET VARIABLES
$ftp = "ftp://XXX.com/"
$user = 'UserName'
$pass = 'Password'
$folder = 'FTP_Folder'
$target = "C:\Folder\Folder1\"
#SET CREDENTIALS
$credentials = new-object System.Net.NetworkCredential($user, $pass)
function Get-FtpDir ($url,$credentials) {
$request = [Net.WebRequest]::Create($url)
$request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
if ($credentials) { $request.Credentials = $credentials }
$response = $request.GetResponse()
$reader = New-Object IO.StreamReader $response.GetResponseStream()
while(-not $reader.EndOfStream) {
$reader.ReadLine()
}
#$reader.ReadToEnd()
$reader.Close()
$response.Close()
}
#SET FOLDER PATH
$folderPath= $ftp + "/" + $folder + "/"
$files = Get-FTPDir -url $folderPath -credentials $credentials
$files
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
$counter = 0
foreach ($file in ($files | where {$_ -like "*.txt"})){
$source=$folderPath + $file
$destination = $target + $file
$webclient.DownloadFile($source, $target+$file)
#PRINT FILE NAME AND COUNTER
$counter++
$counter
$source
}
证书来自:PowerShell Connect to FTP server and get files。
然后通过任务PublishBuildArtifacts
将这些下载文件发布到工件中。
希望这会有所帮助。