简体   繁体   English

是否可以在Azure DevOps上的构建管道中下载文件?

[英]Is it possible to download files during the build pipeline on Azure DevOps?

We're starting to use Azure DevOps to build and deploy my application. 我们开始使用Azure DevOps来构建和部署我的应用程序。 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. 我想知道是否可以将所有图像下载到将在构建管道中生成的工件。

My yml pipeline : trigger: - develop 我的yml管道:触发器: - 开发

pool: vmImage: 'windows-latest' pool:vmImage:'windows-latest'

variables: solution: '**/*.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' 变量:解决方案:'** / * .sln'buildPlatform:'任何CPU'buildConfiguration:'Release'

steps: - task: NuGetToolInstaller@0 步骤: - 任务:NuGetToolInstaller @ 0

  • task: NuGetCommand@2 inputs: restoreSolution: '$(solution)' 任务:NuGetCommand @ 2输入:restoreSolution:'$(solution)'

  • task: Npm@1 inputs: command: 'install' workingDir: 'applicationFolder/app' 任务:Npm @ 1输入:命令:'install'workingDir:'applicationFolder / app'

  • task: VSBuild@1 inputs: solution: '$(solution)' msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"' platform: '$(buildPlatform)' configuration: '$(buildConfiguration)' 任务:VSBuild @ 1输入:解决方案:'$(solution)'msbuildArgs:'/ p:DeployOnBuild = true / p:WebPublishMethod = Package / p:PackageAsSingleFile = true / p:SkipInvalidConfigurations = true / p:PackageLocation =“$( build.artifactStagingDirectory)“'platform:'$(buildPlatform)'配置:'$(buildConfiguration)'

  • task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' ArtifactName: 'drop' publishLocation: 'Container' 任务:PublishBuildArtifacts @ 1输入:PathtoPublish:'$(Build.ArtifactStagingDirectory)'ArtifactName:'drop'buateLocation:'Container'

Is it possible to download files during the build pipeline on Azure DevOps? 是否可以在Azure DevOps上的构建管道中下载文件?

The short answer is yes. 简短的回答是肯定的。

There is no out of box task to download the file from FTP server. 从FTP服务器下载文件没有开箱即用的任务。 Only FTP Upload task to upload file to the FTP server not download. 只有FTP上传任务才能将文件上传到FTP服务器而不下载。

So, to resolve it, we could use powershell scripts to connect to FTP server and download files: 因此,要解决它,我们可以使用powershell脚本连接到FTP服务器并下载文件:

Scripts like: 脚本如:

#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
}

Certificate comes from: PowerShell Connect to FTP server and get files . 证书来自: PowerShell连接到FTP服务器并获取文件

Then publish those download files to the Artifacts by the task PublishBuildArtifacts . 然后通过任务PublishBuildArtifacts将这些下载文件发布到Artifacts。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Azure DevOps 中,是否可以使用 API 递归地枚举子管道构建工件? - In Azure DevOps, is it possible to enumerate children pipeline build artifacts recursively with API? flutter 使用 azure devops 构建管道 - flutter build pipeline with azure devops 如何在 azure devops 管道中将项目文件复制到构建文件夹中? - How do you copy project files into build folder post-build in azure devops pipeline? .Net Core解决方案在本地构建,但无法在Azure DevOPS管道上构建 - .Net Core solutions build locally, but fails build on Azure DevOPS pipeline 在离线服务器上构建 Azure Devops Pipeline - NuGet 包? - Azure Devops Pipeline build on OFFLINE server - NuGet packages? 尝试在 Azure DevOps Pipeline 中构建时未找到项目文件 - Project File Not Found while attempting build in Azure DevOps Pipeline Azure DevOps Pipeline Build 在 GAC 中丢失 DLL 引用失败 - Azure DevOps Pipeline Build fails missing DLL reference in GAC Azure Devops 管道中的警告是否会影响构建时间 - Does Warnings in Azure Devops pipeline affects the build time Azure 构建管道无法从 azure 工件下载依赖项, - Azure build pipeline unable to download the dependences from azure artifact, 如何将内部版本号添加到Azure DevOps中的构建管道工件的名称中? - How do I get the build number into the name of the build pipeline artifact in Azure DevOps?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM