Search code examples
c#azure-devopsazure-pipelinesazure-pipelines-build-taskazure-artifacts

How to publish specific files using Publish Build Artifact Task


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.

enter image description here 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.


Solution

  • 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