问题描述
我们开始使用 Azure DevOps 来构建和部署我的应用程序.目前,我们不将应用程序图像上传到我们的存储库.我想知道是否可以将所有图像下载到将在构建管道期间生成的工件.
We're starting to use Azure DevOps to build and deploy my application. Currently, we do not upload the application images to our repo. I Would like to know if I could download all the images to the artifact that is going to be generated during the build pipeline.
我的 yml 管道:扳机:- 开发
My yml pipeline :trigger:- develop
池:vmImage: 'windows-最新'
pool: vmImage: 'windows-latest'
变量:解决方案:'**/*.sln'buildPlatform: '任何 CPU'构建配置:'发布'
variables: solution: '**/*.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release'
步骤:- 任务:NuGetToolInstaller@0
steps:- task: NuGetToolInstaller@0
任务:NuGetCommand@2输入:restoreSolution: '$(solution)'
task: NuGetCommand@2inputs:restoreSolution: '$(solution)'
任务:Npm@1输入:命令:'安装'workingDir: 'applicationFolder/app'
task: Npm@1inputs:command: 'install'workingDir: 'applicationFolder/app'
任务:VSBuild@1输入:解决方案:'$(解决方案)'msbuildArgs: '/p:DeployOnBuild=true/p:WebPublishMethod=Package/p:PackageAsSingleFile=true/p:SkipInvalidConfigurations=true/p:PackageLocation="$(build.artifactStagingDirectory)"'平台:'$(构建平台)'配置:'$(buildConfiguration)'
task: VSBuild@1inputs:solution: '$(solution)'msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'platform: '$(buildPlatform)'configuration: '$(buildConfiguration)'
任务:PublishBuildArtifacts@1输入:PathtoPublish: '$(Build.ArtifactStagingDirectory)'工件名称:'掉落'发布位置:'容器'
task: PublishBuildArtifacts@1inputs:PathtoPublish: '$(Build.ArtifactStagingDirectory)'ArtifactName: 'drop'publishLocation: 'Container'
推荐答案
简短的回答是肯定的.
没有从 FTP 服务器下载文件的开箱即用任务.只有 FTP 上传任务 将文件上传到 FTP 服务器而不是下载.
There is no out of box task to download the file from FTP server. Only FTP Upload task to upload file to the FTP server not download.
所以,为了解决这个问题,我们可以使用powershell脚本连接到FTP服务器并下载文件:
So, to resolve it, we could use powershell scripts to connect to FTP server and download files:
脚本如下:
#FTP Server Information - SET VARIABLES
$ftp = "ftp://XXX.com/"
$user = 'UserName'
$pass = 'Password'
$folder = 'FTP_Folder'
$target = "C:FolderFolder1"
#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连接FTP服务器并获取文件.
然后通过任务 PublishBuildArtifacts
将这些下载文件发布到 Artifacts.
Then publish those download files to the Artifacts by the task PublishBuildArtifacts
.
希望这会有所帮助.
这篇关于是否可以在 Azure DevOps 上的构建管道期间下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!