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.
Related
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
I was trying to create a release pipeline in Azure DevOps.
All part works fine but getting error in IIS Web Deploy.
More than one package matched with specified pattern: %s. Please restrain the search pattern.
Here is the task for Web Deploy.
I have the yml as:
trigger:
- main
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:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
zipAfterPublish: true
arguments: '--output $(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)
artifactName: AspNetCoreExample
More than one package matched with specified pattern: %s. Please restrain the search pattern
The zip files are came from your build pipeline. if you need only the .zip so configure your build pipeline publish artifacts task to take only this.
However, you have publish your project by the task VSBuild and DotNetCoreCLI:publish. In this case, you will have one more .zip file in your artifact, which will cause that issue.
- 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)'
- task: DotNetCoreCLI#2 #Move this task.
inputs:
command: 'publish'
publishWebProjects: true
zipAfterPublish: true
arguments: '--output $(build.artifactstagingdirectory)'
To resolve this issue, please move the task - task: DotNetCoreCLI#2 and make sure you have only one package in your .zip file.
I've been attempting to create a YAML pipeline in Azure DevOps (Version Dev17.M153.3).
I created a simple Hello World C# console app and checked it into our locally hosted Azure-Git repo. I created my azure-pipelines.yml file and have tried various combinations of things in it including:
The ".NET Desktop" configuration
The "Starter Pipeline" configuration
A file from another C# project that I know works
A file form another project, with various mods to match my test project
A completely commented-out file
A completely blank file
However, every time I try to do a build, I get the following failure message:
/azure-pipelines.yml (Line: 1, Col: 1): A sequence was not expected
Given the error always occurs on line 1 and I've tried lots of different content in the file, I think something else must be configured incorrectly, rather than a problem with the YAML.
Does anyone have any ideas what I'm doing wrong, please?
Various Google searches find pages with similar errors, but none of the solutions helped me.
*** Edited to add various YAML file attempts:
I currently have a completely empty YAML file, but still get the error.
Previous files have included:
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '.'
---------------------------------
variables:
solution: 'HelloWorldCsharpSandpit.sln'
- task: VSBuild#1
displayName: 'Build solution (debug)'
inputs:
solution: '$(solution)'
vsVersion: 16.0
platform: x86
configuration: Debug
clean: true
timeoutInMinutes: 10
---------------------------------
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# [Link removed to avoid odd formatting.]
trigger:
- master
pool:
name: 'Default'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
---------------------------------
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
#
#trigger:
#- master
#
#pool:
# name: 'Default'
#
#variables:
# solution: '**/*.sln'
# buildPlatform: 'Any CPU'
# buildConfiguration: 'Release'
#
#steps:
#- task: NuGetToolInstaller#0
#
#- task: NuGetCommand#2
# inputs:
# restoreSolution: '$(solution)'
#
#- task: VSBuild#1
# inputs:
# solution: '$(solution)'
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
#
#- task: VSTest#2
# inputs:
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
---------------------------------
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
You have here mixed few pipelines.
Here is one:
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# [Link removed to avoid odd formatting.]
trigger:
- master
pool:
name: 'Default'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSBuild#1
displayName: 'Build solution (debug)'
inputs:
solution: '$(solution)'
vsVersion: 16.0
platform: x86
configuration: Debug
clean: true
timeoutInMinutes: 10
Here another but commented:
---------------------------------
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
#
#trigger:
#- master
#
#pool:
# name: 'Default'
#
#variables:
# solution: '**/*.sln'
# buildPlatform: 'Any CPU'
# buildConfiguration: 'Release'
#
#steps:
#- task: NuGetToolInstaller#0
#
#- task: NuGetCommand#2
# inputs:
# restoreSolution: '$(solution)'
#
#- task: VSBuild#1
# inputs:
# solution: '$(solution)'
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
#
#- task: VSTest#2
# inputs:
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
And once more:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
If you modify you pipeline on the portal you can validate using this button:
Then you will get feedback if all is fine with your pipeline.
If you still have this issue
delete your pipeline from portal
delete your file from repo
start with template from portal
run it
adjust it to your need on portal and validate before saving changes
- 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 :)
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