Release pipeline deploy multiple websites from single zip file - iis

I'm attempting to build and deploy two applications that are in the same repository, onto a windows VM.
I would like it to deploy all the web applications into virtual applications matching the site names.
my build step is just a standard bare bones vsbuild:
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
... standard stuff ...
- task: VSBuild#1
inputs:
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)\WebApp.zip"'
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
This generates a single zip file called webapp.zip. Looking in the zip file and it has the following structure
D_C
-> a
-> 1
-> s
-> app1
-> release
-> netcoreapp2.1
-> PubTmp
-> Out
-> <expected content>
-> app2
-> release
-> netcoreapp2.1
-> PubTmp
-> Out
-> <expected content>
Sub question - why did I get the obj folders not the bin folders?
My release, again, is just a single task with a single task "iis web app deploy". For now, I'm just leaving it as Default Web Site.
Leaving the deploy task just as default and I get no sub folders or virtual applications and it dumps app1 into the root of the web site host folder
I've tried defining two release tasks, specifying both app1 and app2 as the virtual application and although on the surface it appears to work (I get a folder called app1 and a folder called app2) both folders contain the code for app1.
Although it obviously refers to TFS rather than devops, https://devblogs.microsoft.com/devops/deploying-an-azure-web-site-using-the-new-build-system-in-visual-studio-online/ perfectly describes what I'm trying to do but yet doesn't seem to be working.

Release pipeline deploy multiple websites from single zip file
Based on my test, the IIS web app deploy task will deploy the files under the Out folder.
Vsbuild generates a zip folder, we cannot classify and deploy the two apps in the zip folder.
Since your websites are in the same zip file, you could add Extract files task to extract the zip file.
Then you could directly use the unzipped folder(app1 -> Out and app2 -> Out) to deploy.
Here is an example:
In the IIS deploy task, you could set the output folder to the Package or Folder.
For example:
You need to hard code the corresponding folder path directly.
e.g.
$(System.ArtifactsDirectory)\Destination folder name\Content\C_C\xxxxx\s\MvcMovie\MvcMovie\obj\Release\netcoreapp2.2\PubTmp\out
On the other hand, you could change the VSBuild arguments.
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)" /p:DeployIisAppPath="Default Web Site"
Then it will generate two zip files for the corresponding app.
In this case, it can make your deployment process clearer.

Related

I want to create a CICD for my azure repo which has multiple projects in its subfolders

My azure repo has multiple projects in it (it is not a single solution with multiple projects), which are placed in subfolders. How to publish artifacts separately for each of the project, which are placed in different folders.
By using paths include statements you can specify a build file and a trigger for each of the subdirectories.
An example below
trigger:
branches:
include:
- refs/heads/Development
paths:
include:
- slapi
- slapi.Common
batch: True
name: $(date:yyyyMMdd)$(rev:.r)
This allows each subdirectory to trigger and build to a separate output directory as needed.
In Azure Devops you then import this build YAML file to create your build pipeline and then when you create your release pipeline you select this build pipeline as the source for the drop files
Obviously you need to complete the above example file with the actual build configuration but since the question was about using subdirectories I included the relevant parts.
For your working directories use the variables section like this to specify the project at hand
variables:
vmImageName: "windows-2022"
workingDirectory: "projectName" <- change this to your real project name
then refer to the variables in your build task like this
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: "build"
projects: |
$(workingDirectory)/*.csproj
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release

Azure Pipeline - C# Build project depending on another project in another repository

I have the following situation:
On AzureDevops:
Project A -
Repository A
Module3/Module3.csproj
Module1/Module1.csproj
Module2/Module2.csproj
Module1/Module1.csproj
- Solution.sln
Project B -
Repository B
ModuleCore/ModuleCore.csproj
-ModuleCore.sln
ModuleCore is added to several projects.
In VisualStudio, when we are going to compile project A , I add ModuleCore.csproj as an existing project, and the compilation works.
I've done several pipelines on azure devops, with no dependency between projects, but with this one I'm having difficulty.
When I try to do the Build, it doesn't find the ModuleCore and breaks.
My current build task is:
- 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)'
How do I build Project A and link Project B as a dependency?
Is there any other way to perform this Build in the pipeline?
As Modulecore is being used in several projects, assuming it's a library it's best adding it to nuget (organisation level) repository and restore it while building the main solution.

What's should I specify for the rootDirectory of an Azure Pipeline for a static website?

I manage a static website. No database, no server-side processing like ASP.NET (IIS), PHP, etc. This website is comprised of just HTML, CSS, some JavaScript, and a few graphic files. I'm trying to use Azure Pipelines for this. This is my first time using Azure Pipelines. I chose an HTML template to start the YAML pipeline.
I'm using the FTP Upload task. The source code is in Azure DevOps Repos. I'm testing the Pipeline by trying to FTP the files to a test folder on the hosting server (not a part of Azure). In testing the pipeline, I get this error:
##[error]Error: Failed find: ENOENT: no such file or directory, stat '/bin/pyvenv'
I don't know what I should put as the rootDirectory. I thought it appropriate to put the "/". Here's the YAML:
# HTML
# Archive your static HTML project and save it with the build record.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- none
pool:
vmImage: 'ubuntu-latest'
steps:
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(build.sourcesDirectory)'
includeRootFolder: false
- task: FtpUpload#2
inputs:
credentialsOption: 'inputs'
serverUrl: 'ftp://ftp.destination.com'
username: '$(TheUsername)'
password: '$(ThePassword)'
rootDirectory: '/'
filePatterns: '**'
remoteDirectory: '/test'
clean: false
cleanContents: false
preservePaths: false
trustSSL: false
What should I put for the rootDirectory?
Have you tried
rootDirectory: '.'
OR
rootDirectory: '$(Pipeline.Workspace)' ?
The task ArchiveFiles field archiveFile default value is $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip.
According to your YAML build definition, you have archived the folder $(build.sourcesDirectory) to the path $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip, and next task is FtpUpload, then field rootDirectory should be $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip and it will upload the zip file to a remote machine.
If you want to upload the static website, you could also set the field rootDirectory to $(Build.SourcesDirectory). Check the doc build variables for more details.
The root directory is your source code directory from where your compiled code is, in your case it should be checkout path.
I think you should use should use $(System.DefaultWorkingDirectory)/rootFolderName.
Here root folder should be your repo name. You try printing the content of the $(System.DefaultWorkingDirectory) to check whether you need to use $(System.DefaultWorkingDirectory) only or any nested folder inside it.

Why Azure Devops File Copy static website not copying to root?

I have a problem deploying my angular app to Azure storage static website. I created a CI/CD pipeline last year, I was using it for months. There was no deployment in the past few months, and with today's deployment I ran into some problems.
The first problem was about authentication, but I was able to solve it.
The second is the one I'm struggling with. I run the release pipeline, and the files are copied, but not in the $web container root, but it creates a 'prod' folder, and copies files there. Because of this, I can not open the website, as it searches for the 'index.html' file in the $web root folder, and obviously doesn't find it, as it is in the $web/prod folder. I can open the file going to /prod URL, but then it tries to load all resources from the root (so not the prod folder), and obviously the files aren't there.
I looked at some articles about deploying to static webiste storage account, and all of them showed similar yamls to what I'm using.
Here's my build pipeline which publishes the artifacts after build:
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/dist/prod'
ArtifactName: 'prod'
publishLocation: 'Container'
displayName: 'publish prod'
And here is the file copy task:
- task: AzureFileCopy#4
displayName: 'AzureBlob File Copy'
inputs:
SourcePath: '$(System.DefaultWorkingDirectory)/_angularApp CI/prod'
azureSubscription: '***'
Destination: AzureBlob
storage: angularApp
ContainerName: '$web'
The files are there after the 'PublishBuildArtifact' task, they are copied, just not in the correct folder ($web root). Does anybody have an idea?
Thanks
Usually, without specifying Blob Prefix, the content in the specified folder is copied to the root of the container by default.
Tested on my side, it works well:
You can check whether your publish source directory contains a folder named prod and copy this folder to the container.
In addition, the AzureFileCopy#3 version I used here, you can try to use V3 azure copy file task.

Azure - Publish Web API - Compile

I'm trying to use a DevOps pipeline to deploy a Web API. I've got it working, looks great.
However, when the files are copied for the artifact, all of the source files are there too. When I use Visual Studio to "Publish" my Web API, there are minimal files, single Web.config (not Web.Release.config, Web.Debug.config)
Is there a way I can achieve this or, do I run a clean-up script to bin off the files I don't want there.
Example - published with Visual Studio:
Example - published with Azure:
Edit:
Created task group which goes through and deletes the unnecessary files and directories - not sure this is the correct approach but it does work.
As you know, First of all you should publish your source on Azure
e.g.
- task: UseDotNet#2
inputs:
packageType: 'sdk'
version: '3.1.x'
- script: dotnet publish --self-contained -r win-x64
displayName: 'dotnet build $(buildConfiguration)'
Then use your published files for your artifact.
e.g.
bin/Debug/netcoreapp3.1/win-x64/publish
You don't need to remove anything for this purpose.

Resources