Pipeline for dotnetcore app to deploy on azure
Asked by rajputj3@bv.com:

Can someone please help me with building dotnetcore api app and deploy on Azure?

This is what I have so far.

# Template .NET Core build # This template allows you to validate your .NET Core package. # The workflow allows running tests and code linting on the default branch. # To run your pipeline on a Windows machine, create a self-hosted Windows runner. # For instructions on setting up a Windows runner, see <https://support.atlassian.com/bitbucket-cloud/docs/set-up-runners-for-windows/> image: atlassian/default-image:2 pipelines: branches: master: - step: name: Build and Test image: mcr.microsoft.com/dotnet/core/sdk:3.1 caches: - dotnetcore script: - export PROJECT_NAME=Web/Web.csproj - dotnet restore - dotnet build $PROJECT_NAME - dotnet publish $PROJECT_NAME --configuration Release -r win-x64 --no-self-contained --output dist - pipe: snyk/snyk-scan:1.0.1 variables: SNYK_TOKEN: $SNYK_API_TOKEN LANGUAGE: "node" # Required unless SNYK_TEST_JSON_INPUT is set IMAGE_NAME: "" # Only required if LANGUAGE set to "docker" SNYK_BASE_IMAGE: "" # Custom base image CODE_INSIGHTS_RESULTS: "true" # Optional. SNYK_TEST_JSON_INPUT: "" # Optional. The filename or path of a JSON file containg the output from running a test with the Snyk CLI (with json output option). PROTECT: "" # Optional. DONT_BREAK_BUILD: "" # Optional. MONITOR: "true" # Optional. SEVERITY_THRESHOLD: "\<low\|medium\|high\|critical\>" # Optional. ORGANIZATION: "" # Optional. PROJECT_FOLDER: "from-azure-devops" # Optional. TARGET_FILE: "" # Optional. EXTRA_ARGS: "all-projects" # Optional. DEBUG: "" # Optional. SNYK_API: "" # Optional. artifacts: - dist/\*\* - step: name: Build zip script: - mv dist Web - zip -r Web.zip Web artifacts: - Web.zip # pass file to the next step - step: name: "Deploy to Test" deployment: test script: - pipe: atlassian/azure-web-apps-deploy:1.2.1 variables: AZURE_APP_ID: $AZURE_APP_ID AZURE_PASSWORD: $AZURE_PASSWORD AZURE_TENANT_ID: $AZURE_TENANT_ID AZURE_RESOURCE_GROUP: 'oneclick_002_test' AZURE_APP_NAME: 'web-oneclick-test-02' ZIP_FILE: 'Web.zip![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/332159i8C786E23010377E4/image-size/large?v=v2&px=999 "image.png")


Answers:
author: Mark C
body: Hi [rajputj3@bv.com](/t5/user/viewprofilepage/user-id/5467490)  

Thank you for reaching out to the community.

You can check the following documentation on how to deploy to Microsoft Azure.

* [Deploy to Microsoft Azure](https://support.atlassian.com/bitbucket-cloud/docs/deploy-to-microsoft-azure/)
* [How build a NET 6.0 pipeline](https://community.atlassian.com/t5/Bitbucket-questions/How-build-a-NET-6-0-pipeline/qaq-p/2084075)

Regards,  
Mark C

comments: author: rajputj3@bv.com
body: Thank you for your reply. I have another issue as well. Please see below.

I got deployment working. Now I am trying to figure out how to send deployment variables. Do you have any idea?

For example - I am trying this but it does not set the value of the variable.

- step:

name: Build Web zip script:

- cd wwwroot # go into the folder

- contents="$(jq '.ConnectionStrings.Redis = "{{$ConnectionStrings_Redis}}"' appsettings.json)" \&\& \\ -

echo -E "${contents}" \> appsettings.json

- cat appsettings.json

- zip -r Web.zip . # build a zip file for contents and their subfolders to avoid main "wwwroot" within the zip file

- mv Web.zip .. # move out the zip file so it can send to next step as artifacts

artifacts:

- Web.zip # pass file to the next step

It is replacing as shown below:

![](blob:https://blackveatch.atlassian.net/366f35c8-a10a-4f3b-b957-e77ae6445bce#media-blob-url=true&id=c13cf5e1-fdfb-438b-8063-f1cdc3ffb34d&contextId=22677&collection=)![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/333044i1891D7ECE55D8F5E/image-size/large?v=v2&px=999 "Capture.PNG")


author: Mark C
body: Hi [rajputj3@bv.com](/t5/user/viewprofilepage/user-id/5467490)  

Could you try to export the file as an artifact and open it locally?

See if the variable has been passed correctly because you won't be able to view the variable on Bitbucket Cloud Pipelines build UI if the variable is secured for security reasons.  

Regards,  
Mark C


author: rajputj3@bv.com
body: I have .env.production file which contains 5 variables like this  
VUE_APP_AUTHORITY= #{Authority}#  
VUE_APP_CLIENT_ID= #{Client_Id}#  
I would like to update the .env file during build to replace #{Authority}# value reading from the repository variables.  
Do you know how to do this? Please help.  
Thank you.


author: Mark C
body: Hi [rajputj3@bv.com](/t5/user/viewprofilepage/user-id/5467490)  

I personally recommend using "sed" tool to change your configuration file on the fly. You can check this link for more information. - [How to Install and Use 'sed' Command in Linux](https://ioflood.com/blog/install-sed-command-linux/)  

Regards,  
Mark C


author: rajputj3@bv.com
body: Ok, I will take a look.

Thank you for your reply.


Tags: bitbucket-cloud

cloud