How to publish specific files using Publish Build Artifact Task

ぃ、小莉子 提交于 2021-01-29 07:23:36

问题


I am Building C# Application using Visual Studio Build In Azure Pipeline.

My solution Contains multiple project (ManagerWeb & WebAPI).

I want to Publish Two Separate Artifact ManagerWeb & WebAPI respectively.

All the required File's are present in Build.ArtifactStagingDirectory.

How I can specify a pattern using which I can get Two Separate Artifact ? Example All the File name with WebAPI in 1st Artifact & ManagerWeb in another.

The File name from ArtifactStaging Directory are as Below

Something.Manager.WebAPI.deploy.cmd
Something.Manager.WebAPI.deploy-readme.txt
Something.Manager.WebAPI.SetParameters.xml
Something.Manager.WebAPI.SourceManifest.xml
Something.Manager.WebAPI.zip

Something.ManagerWeb.deploy.cmd
Something.ManagerWeb.deploy-readme.txt
Something.ManagerWeb.SetParameters.xml
Something.ManagerWeb.SourceManifest.xml
Something.ManagerWeb.zip

Any Help will be appreciable.

Thanks in Advance.


回答1:


Add a PowerShell task to create two folders and move the files to there:

cd $(Build.ArtifactStagingDirectory)
$files = dir
mkdir WebAPI
mkdir ManagerWeb
ForEach($file in $files)
{
   if($file.FullName.Contains("WebAPI"))
   {
       mv $file.FullName -Destination WebAPI
   }
   else
   {
       mv $file.FullName -Destination ManagerWeb
   }      
}

Then in the "Path to publish" field add the folders:

For WebApi artifacts:

$(Build.ArtifactStagingDirectory)/WebAPI

And for ManagerWeb artifacts:

$(Build.ArtifactStagingDirectory)/ManagerWeb



回答2:


Add two Copy Files steps which copy;

  • ManagerWeb files to $(Build.ArtifactStagingDirectory)\ManagerWeb
  • WebAPI files to $(Build.ArtifactStagingDirectory)\WebAPI

Then have two Publish Artifact steps to;

  • Publish $(Build.ArtifactStagingDirectory)\ManagerWeb as ManagerWeb
  • Publish $(Build.ArtifactStagingDirectory)\WebAPI as WebAPI

I've mocked this up and exported the YAML as follows;

pool:
  name: Hosted VS2017
steps:
- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)\ManagerWeb'
  inputs:
    SourceFolder: 'your/path/here/ManagerWeb'
    TargetFolder: '$(Build.ArtifactStagingDirectory)\ManagerWeb'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)\WebAPI'
  inputs:
    SourceFolder: 'your/path/here/WebAPI'
    TargetFolder: '$(Build.ArtifactStagingDirectory)\WebAPI'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: ManagerWeb'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)\ManagerWeb'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: WebAPI'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)\WebAPI'


来源:https://stackoverflow.com/questions/56377787/how-to-publish-specific-files-using-publish-build-artifact-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!