How to publish specific files using Publish Build Artifact Task - c#

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.

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'

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

Related

Deploy C# MVC app to a specific virtual path without overwriting default site using azure pipelines

I'm trying to deploy a c# MVC app to windows server running IIS where I have deployed another app as default site but this app which I want to build and deploy is only to a specific virtual folder
so for build steps I have used below steps :
paths:
exclude:
- gitignore
pool:
name: 'Hosted Windows 2019 with VS2019'
variables:
SolutionPath: '**/*.sln'
buildConfiguration: 'Release'
buildPlatform: 'Any CPU'
stages:
- stage: Build
displayName: Build app
jobs:
- job: Build
workspace:
clean: all
displayName: Build app
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(SolutionPath)'
- task: VSBuild#1
displayName: 'Build solution'
inputs:
solution: '$(SolutionPath)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.stagingdirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: $(Build.artifactstagingdirectory)
ArtifactName: 'drop' ```
As you can see I have set the msbuildArgs specially /p:WebPublishMethod=FileSystem to drop the files under virtual specific path.
as a outcome the build artifacts are coming out as a long path,not sure if I am missing something in terms of setting any argument for path to publish-
\drop\Archive\Content\D_C\a\1\s\temp\obj\Release\Package\PackageTmp\<app files>
Now in release pipeline I have used below IIS web app deploy task
[![Release pipeline][1]][1]
[1]: https://i.stack.imgur.com/Dkp7m.png
can someone explain me how do I should build it a specific virtual path so I can deploy it without interfering the default site

How do you build individual project artifacts in azure deveops pipeline

I have multiple projects contained in my repo that I would like to build individual zip artifact to deploy them each separately. Currently, the pipeline builds one zip artifact that contains all the projects. How do I configure my azure-pipelines.yml file to accomplish this task? Below is my current file.
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
/p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip"
/p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
It depends on how you define the MSBuild arguments. The /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site" is the direct cause of the issue, it calls msbuild to package all projects into one WebApp.zip file.
With msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"' you can have separate ProjectName.zip files under $(build.artifactStagingDirectory) path.
And then you can use one Publish Build Artifact task to publish whole $(build.artifactStagingDirectory) directory which contains ProjectA.zip, ProjectB.zip...
Also you can use several Publish Build Artifact tasks in one pipeline for your several output xx.zip files.
You can change the build parameter /p:PackageAsSingleFile=false which will prevent all the projects from being zipped together. If you want to move the built files after the build, before the Publish Artifacts step, you can create a Copy files task that will copy the project's build folder to another location within the
'$(Build.ArtifactStagingDirectory)'
steps:
task: CopyFiles#2
displayName: 'Copy Project Files'
inputs:
SourceFolder: '$\ProjectName\bin$(BuildConfiguration)'
Contents: '****'
TargetFolder: '$(build.artifactstagingdirectory)\ProjectName'
CleanTargetFolder: true
Though these will all still be placed within the 'drop' folder or whatever the $(build.artifactstagingdirectory) is called. The only way to separate artifacts is to create separate pipelines for each project.

When deploying through Azure DevOps getting error: You do not have permission to view this directory or page

When I am deploying the web application using DevOps pipeline I am getting this error: "You do not have permission to view this directory or page." I figured out that when I deploy it manually with the "publish" button there is no initial folder in uploaded files, but when uploaded through Azure DevOps there are initial folders with all the projects, any ideas?
files structure when deployed from "publish" button directly from VS (working)
files structure when deployed from Azure DevOps (not working)
the error: You do not have permission to view this directory or page
when open swagger UI: The resource you are looking for has been removed, had its name changed or is temporarily unavailable.
azure-pipelines.yaml file :
trigger:
- master
pool:
name: Hosted Windows 2019 with VS2019
demands: npm
variables:
buildConfiguration: 'Release'
steps:
- task: Npm#1
displayName: 'angular-cli'
inputs:
workingDir: src/Kronova.MovingPortal.Web.Host
verbose: false
- task: Npm#1
displayName: 'ng build'
inputs:
command: custom
workingDir: src/Kronova.MovingPortal.Web.Host
verbose: false
customCommand: 'run publish-full'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: dist'
inputs:
PathtoPublish: src/Kronova.MovingPortal.Web.Host/wwwroot
ArtifactName: dist
- task: UseDotNet#2
displayName: 'Use .NET SDK 3.1'
inputs:
packageType: 'sdk'
version: '3.1.x'
- task: DotNetCoreCLI#2
displayName: 'Restore project dependencies'
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
displayName: 'Build the project - $(buildConfiguration)'
inputs:
command: 'build'
arguments: '--no-restore --configuration $(buildConfiguration)'
projects: |
**/*.csproj
!**/*Mobile*.csproj
!**/*Client*.csproj
!**Kronova.MovingPortal.Application.Client/**
- task: DotNetCoreCLI#2
displayName: 'Publish the project - $(buildConfiguration)'
inputs:
command: publish
projects: |
**/*.csproj
!**/*Mobile*.csproj
!**/*Client*.csproj
!**Kronova.MovingPortal.Application.Client/**'
publishWebProjects: false
arguments: '--no-build --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
zipAfterPublish: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: Estimated_Pad_Api'
condition: succeeded()
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'Estimated_Pad_Api'
publishLocation: 'Container'

How can I share a built .NET Core project between many jobs in Azure pipelines?

- job: buildAndTestJob
steps:
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
vstsFeed: $(vstsFeed)
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
arguments: '--configuration ${{ parameters.buildConfiguration }}'
- task: DotNetCoreCLI#2
displayName: 'dotnet test'
inputs:
command: test
arguments: '--configuration ${{ parameters.buildConfiguration }}'
- task: CopyFiles#2
displayName: copy bin files
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: '**/bin/**/*'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: CopyFiles#2
displayName: copy obj files
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: '**/obj/**/*'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
displayName: publish build artifacts
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: buildeffect
publishLocation: 'Container'
-job: packAndPushJob
steps:
- task: DownloadBuildArtifacts#0
displayName: download build artifacts
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'buildeffect'
downloadPath: '$(Build.ArtifactStagingDirectory)'
- task: CopyFiles#2
displayName: copy files to source directory
inputs:
sourceFolder: '$(Build.ArtifactStagingDirectory)/buildeffect'
contents: '**/*'
TargetFolder: '$(Build.SourcesDirectory)'
allowPackageConflicts: true
- task: DotNetCoreCLI#2
displayName: 'dotnet pack'
inputs:
arguments: '--no-restore'
nobuild: true
command: pack
projects: '$(Build.SourcesDirectory)'
publishWebProjects: true
publishVstsFeed: $(vstsFeed)
includeNuGetOrg: true
- task: NuGetCommand#2
displayName: 'nuGet push'
inputs:
command: push
projects: '$(Build.SourcesDirectory)'
publishVstsFeed: $(vstsFeed)
allowPackageConflicts: true
I have 2 jobs. First, to restore, test, build and share build files in a build artifact. Second to pack and push nuget packages. First job finished their job with success, but second job failed during pack task. It have a problem with nuget packages, for example:
/usr/share/dotnet/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package Microsoft.CSharp, version 4.6.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/home/vsts/work/1/s/src/Spotio.Leads.Client/Spotio.Leads.Client.csproj]
So, maybe should we share builded project in another way? Or maybe add some parameters with feeds to restore? I don't have any idea, so please, if you have any suggestions, help us :)
How can I share a built .NET Core project between many jobs in Azure
pipelines?
1.See this : Projects using the PackageReference format always use packages directly from this folder(%userprofile%\.nuget\packages).
2.Project that targets .net core uses PackageReference format, so the restored packages are stored in %userprofile%\.nuget\packages in first agent.
3.For your second agent job, devops actually start another hosted agent to run your tasks. It means for second agent, it doesn't have the referenced packages in %userprofile%\.nuget\packages.
4.Something we should know is that: Though we've copied all files of bin and obj to second agent, dotnet pack xx.csproj will still try to confirm the referenced packages exist, then the issue occurs.
So I suggest you can add a dotnet restore task before that dotnet pack task in second agent job to make sure the missing packages can be found in second agent.
Note:
1.In one build pipeline with two agent jobs, though these two agent jobs all use hosted agent, these two agent is not the same instance.
2.Make sure the configuration you use to build is the same configuration you use to pack.
Hope it helps. If i misunderstand anything, feel free to let me know :)

How to release and publish downloadable binaries?

How do I configure Azure DevOps to publish binaries in a web downloadable form, and automatically update my readme.md or wiki page to reflect the latest released artifacts?
I know how to build release pipelines for artifacts I publish to Azure, e.g. I can publish webapps and functions.
But I can't figure out how to publish and release dowloadable content.
I'd like the result to be similar to GitHub releases, where my users can browse releases, and click and download the files.
I'd like the project page (readme.md or wiki) to automatically be updated with the release data, similar to how I would create a build state link.
If you want to upload the artifacts to your shared path. I recommend that you could add the script task to upload the released artifacts to the shared path or ftp server.
For example, if azure storage is acceptable, then you could publish your build artifacts to the Azure storage with following scripts
$source = "build file"
$azureStorageKey = "xxxxx"
$storage_context = New-AzureStorageContext -StorageAccountName "yourstorageAccount" -StorageAccountKey "$azureStorageKey"
Set-AzureStorageBlobContent -Context $storage_context -Container "containerName" -File $source -Blob "drop.zip" -Force
I'd like the project page (readme.md or wiki) to automatically be updated with the release data, similar to how I would create a build state link.
Yes, you could to do that with Azure pipeline build state badge. You could copy the markdown link into your readme file
Update :
I do a demo upload the build to azure storage with following YAML file.
queue:
name: Hosted VS2017
demands:
- msbuild
- visualstudio
- azureps
steps:
- task: NuGetCommand#2
displayName: 'NuGet restore'
- task: VSBuild#1
displayName: 'Build solution **\*.sln'
- task: CopyFiles#2
displayName: 'Copy Files'
inputs:
SourceFolder: '$(build.sourcesdirectory)'
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
- task: ArchiveFiles#2
displayName: 'Archive $(Build.ArtifactStagingDirectory)'
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
- task: AzureFileCopy#1
displayName: 'AzureBlob File Copy'
inputs:
SourcePath: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
azureSubscription: xxxxx
Destination: AzureBlob
storage: $(storageAccountName)
ContainerName: $(containerName)
UI design:
what I'd like is for the page to have a download link that points to the latest build that passed.
We could use AzureBlob File Copy task to copy the build easily to the Azure blob storage.
If Azure function is possible, you could use the blob trigger to create your customized page with your script.

Categories

Resources