VSTS Continuous Integration - ASP.NET Core and Angular 4 project -
i have asp.net core web app (vs2017) , develop angular 4 front-end project (vs code) should part of core web app. , need set ci whole thing. so, when changes in either of projects, builds angular 4 first, gets artifacts , puts them asp.net core project, build , publish azure.
at moment, have angular 4 project in separate repo. so, ideally, can set ci on repo , make publish artifacts azure storage (for example). then, i'd have ci setup asp.net core repo trigger build, first step 'get angular 4 artifacts , put them in here'. this:
- if file changes in ng4 repo => build , yield build
- it should trigger build of aspnetcore repo
- grab ng4 build , copy inside aspnetcore folder structure (like wwwroot)
- build aspnetcore repo
- ...
- test, deploy, etc
so question - how can vsts?
ok, said have 2 projects - asp.net core mvc project (core-p) , angular 4 project (ng-p). reside in separate repo's in vsts. goal automate build , publishing of whole project azure app service.
here's how made work:
first. ng-p
build tasks:
- 'npm install @angular/cli@latest -g' - add npm task, set
npm commandinstall, setarguments@angular/cli@latest -g. - 'npm install' - installs that's needed ng project.
- build angular 4 project production. made simple build.cmd runs
ng build --aot --output-path dist --base-href work. notice --output-path dist: project output put 'dist' folder (which default angular-cli guess, want make sure). besides, use --base-href work option here, angular 4 app available [mydomain.com]/work in core-p project. - archive files - archive in dist folder (the compiled app). tick replace existing archive.
- put archive azure blob storage. find convenient use azure blob storage make artifact available cope-p build definition. first, blob storage ready, no set required (except need have azure storage account). besides, it's pretty secure, dist.zip not publicly available. can use any other method sharing artifacts between builds. azure file copy task has required params - storage acc name, key, destination container name. set them accordingly, you'll need them in corresponding task core-p build.
- trigger core-p build - when ng-p has artifact uploaded azure blob storage, need trigger build of core-p. in order that, need install trigger build task extension vsts marketplace.
second. core-p
so, have built ng-p , it's available core-p build process dist.zip file sitting in azure blob storage (or other place choose). now, created build definition asp.net core (preview) template. go , create 1 project , change following.
tasks:
- restore (.net core preview) - 1 created template. not change it.
- build (.net core preview) - same
now, need grab dist.zip. in case, grab azure blob storage somehow (if used other way share dist.zip, you'll need use own task it). managed used azure powershell inline script this:
$an = "[your_azure_storage_acc_name]" $ak = "[storage_acc_key]" $ctx = new-azurestoragecontext -storageaccountname $an -storageaccountkey $ak
$blobs = get-azurestorageblob -container "ng-p-dist" -context $ctx $destfolder = "$env:build_artifactstagingdirectory"
new-item -path $destfolder -itemtype directory -force $blobs | get-azurestorageblobcontent -destination $destfolder -context $ctx
this download dist.zip , puts in build.artifactstagingdirectory directory.
extract files - task extracts dist.zip
$(build.artifactstagingdirectory)/$(build.repository.name)/wwwroot/js/app. archive file patterns param set$(build.artifactstagingdirectory)/dist.zip, , destination folder$(build.artifactstagingdirectory)/$(build.repository.name)/wwwroot/js/apppowershell script - remove dist.zip, don't need anymore. one-liner:
remove-item "$(build.artifactstagingdirectory)/dist.zip"
- test .net core preview - original template.
- publish .net core preview - same
- publish artifact - same
so, creates asp.net core mvc project angular 4 app inside. now, have add 2 things setup:
- cope-p should have trigger based on dist.zip change. so, whenever ng-p changes, creates new dist.zip. , should automagically trigger cope-p build. guess there web hooks involved. i'll add when figure out.
- since i'm new build/release pipeline, have publish project azure app service. should easy, since it's standard task vsts. haven't had change there.
so, hth
Comments
Post a Comment