How to set bin directory in azure pipelines? - azure

I wrote two azure pipelines. One pipeline build my app as a tool and publishes to a artifact feed.
My second pipeline runs that app from artifact feed. Problem is that my app does not see appsettings.json. When I tried to print current directory I saw that is root repo folder. How to solve this?
What have I tried is to set workingDirectory in task that run's tool as:
$(Build.BinariesDirectory)
$(Agent.BuildDirectory)
etc..
So, when I run tool locally and print current directory files i get all DLL's included. But on azure I get repo root.
Is my approach good or completely wrong?

Related

Running Kentico continuous integration on Azure app services

We have a new project in which we are trying to make use of the built in continuous integration in Kentico for tracking changes to templates, page types, transformations etc.
We have managed to get this working locally between two instances of a Kentico database, making changes in one, syncing the changes through CI and then restoring them up to the second database using the Continuous integration application that sits in the bin folder in the Kentico site.
The issue we are having is when it comes to deploying our changes to our dev and live environments.
Our sites are hosted as Azure App services and we deploy to them using VSTS (Azure DevOps) build and release workflows however, as these tasks run in an agent, any powershell script we try to run to trigger the CI application fails because it is not running in the site / server context.
My question is, has anyone managed to successfully run Kentico CI in the context of an Azure app service? Alternatively, how can I trigger a powershell script on the site following a deployment?
Yes, I've got this running in Azure DevOps within the release pipeline itself. It's something that we're currently rolling out as a business where I work.
The key steps to getting this working for me were as follows:
I don't want to deploy the ContinuousIntegration.exe or the repository folders, so I need to create a second artefact set from source control (this is only possible at the moment with Azure Repos and GitHub to my knowledge).
Unzip your deployment package and copy the CMS folder to a working directory, this is where you're going to run CI. I did this because I need the built assemblies available.
From the repo artefact in step 1, copy the ContinuousIntegration.exe and CI repository folders into the correct place in your unzipped working folder.
Ensure that the connection string actually works for the DB in your unzipped folder, if necessary, you may want to change your VS build options in regards to how the web.config is handled.
From here, you should be able to run CI in the new working folder against your target database.
In my instance, as I don't have CI running on the target site it means that everything is restored every time.
I'm in to process of writing this up in more detail, so I'll share here when I've done that.
Edit:
- I finally wrote this up in more detail: https://www.ridgeway.com/blog/web-development/using-kentico-12-mvc-with-azure-devops
We do, but no CI. VSTS + GIT. We store virtual objects in the file system and using git for version control. We have our own custom library that does import export of the Kentico objects (the ones are not controlled by Git).Essentially we have a json file "publishing manifest" where we specify what objects need to be exported (i.e. moved between environments).
There is a step from Microsoft 'Powershell on Target Machines', you guess you can look into that.
P.S. Take a look also at Three Ways to Manage Data in Kentico Using PowerShell
Deploy your CI files to the Azure App Service, and then use a Azure Job to run "ContinuousIntegration.exe"
If you place a file called KenticoCI.bat in the directory \App_Data\jobs\triggered\ContinuousIntegration - this will automatically create a web job that you can can trigger:
KenticoCI.bat
cd D:\home\site\wwwroot
ren App_Offline.bak App_Offline.htm
rem # run Kentico CI Integraton
cd D:\home\site\wwwroot\bin
ContinuousIntegration.exe -r
rem # Removes the 'App_Offline.htm' file to bring the site back online
cd D:\home\site\wwwroot
ren App_Offline.htm App_Offline.bak

Azure DevOps (VSTS) - how to copy a file from the agent VM and into my repo

I'm very confused about how one of the build task currently works.
I have been using Grunt locally in VS-Code to minify a JS file. All seems to be working well. In Azure DevOps, as a Build Task, I am using the same package.json the minification takes place but on the agent VM:
D:\a\1\s\Build\Hello.js
Looking in my repo, this file does not exist. I am assuming that I need to copy the file and upload to my own repo. Does anyone know how I do this?
A build usually creates a build ** artifact** that gets copied to a drop location. You will use the build artifacts inside your release definitions to deploy the binaries / minified or optimized code to an environment.
You probably don't want/need to upload any file back to your repo.
See: What is Azure pipelines

Publish Zip Package from VSTS to Octopus Deploy

I'm trying to deploy an artifact from VSTS to an Azure App Service, using Deploy an Azure Web App step template in Octopus Deploy. The VSTS zip package will have a structure like the following:
\Content\C_C\a\1\s\Api{ProjectName\obj\Release\Package\PackageTmp
When I publish the zip file using MsDeploy.exe. It automatically only copy the folders & files inside the PackageTmp folder into the wwwroot folder. However, when I use the Octopus deploy, It copies all of the folder from Content\. Is there any way to make the Octopus deploy work like using MsDeploy.exe? I'd like to use the zip as is, so adding a Copy Files step or changing the PackageLocation in the VSTS build is not really an option.
Any help/suggestion is really appreciated.
Thank you.
To achieve the layout of the files as you describe, you will have to modify your build step. In the MSBuild arguments section on the build step, ensure you have the following parameters defined:
/p:WebPublishMethod=FileSystem /p:PackageLocation="$(build.artifactstagingdirectory)\\"
These two parameters will create the package in the directory specified by the PackageLocation parameter, and it should be in the format you expect.
In the step where you push the package to Octopus specify this directory as the Package Source.
There isn’t such setting to do it.
You can publish the web app with File System mode , then package the files through Package Application task.

Azure deploy missing XML doc files from deployment target

I have a solution. 2 projects within the solution produce XML documentation, that I need to copy to the bin folder web root when I deploy to azure.
Locally, I notice that when I build my solution, those 2 XML files get copied with the DLL into my web/bin folder. When I run my un-modified deploy.cmd file locally, I also notice that kudosync picks those up and hapilly puts them into my artifacts/wwwroot/bin folder.
But - when I deploy to azure by pushing to github, the local deployment temp folder on azure doesn't contain the XML files, and thus they don't get picked up. I added some post-build "DIR" commands to the deploy.cmd file to see what is going on, and the XML files just aren't there in the %DEPLOYMENT_TEMP%\bin\ folder.
Anyone know what's going on here?
Aha - it's because when you build from MSBUILD, it doesn't generate the XML docs for the related projects. I was getting them locally because I'd at some point built from VS, which generated them.

Teamcity MsBuild generates wrong cspkg file

I am trying to build and Deploy our solution to Azure using TeamCity.
When I Build the azure solution (Web.Azure.ccproj) using TC, it always generates wrong file like Web.Azure.ccproj.cspkg in Release\app.publish folder. I am not understaing why it is generating a file like ccproj.cspkg. Rather it should have just generated Web.Azure.cspkg.
Note: when I try directly in command prompt (msbuild Web.Azure.ccproj /t:Publish) am able to see proper files generated.
Any reason why this is happening?
Thanks in Advance
I don't know why the generated files are different. However, if you are looking to deploy to Azure Cloud Services from TeamCity, maybe this link will help.
The linked post has a powershell script that will deploy the solution and you can include that as a build step in TeamCity. The script deals with having different Live and UAT environments etc, which you may not need.
For what it's worth, we're building the entire solution with a Visual Studio (.sln) runner and it builds the Azure projects fine.
Some of our parameters:
Targets: Rebuild
Configuration: Dev (Could be Stage or Release per our environments)
Command line parameters: /p:TargetProfile=Dev /P:Configuration=Dev
The last set of parameters are where I originally got stuck. We have profiles for Azure projects and configurations for the entire solution. We need both to get the right packages created.

Resources