Same branch, deploy to multiple Web Apps with Travis CI in Azure

My company is working with a C# .NET Core backend and a React frontend. For deployment, I would like for both to be deployed to Azure Web Apps. So far, I have set up two web apps: one for the frontend (this being React) and one for the backend. However, I would like to only have one web app for both, and I really like Travis CI.

  1. How can I deploy both on the same Azure Web App?
  2. If it is not possible, how can I deploy each to separate web apps while encrypting the Travis CI environment variables (like AZURE_WA_USERNAME ) as different values for the branch?

My current .travis.yml looks like this:

jobs:
  include:
    - language: csharp
      solution: abc
      mono: none
      dotnet: 5.0.402
      before_script:
        - cd Backend
      script:
        - dotnet restore
        - dotnet test
      deploy:
        provider: azure_web_apps
        verbose: true
        on: main
    - language: node_js
      node_js:
        12
      before_install:
        - cd Frontend
      install:
        - npm install
      script:
        - npm run lint
        - npm test
        - npm run build
      deploy:
        provider: azure_web_apps
        verbose: true
        on: main

What can I do to make this feasible? Thanks.

Hello @HILLBILLYHeisT,

The short version of this answer is, it’s not possible to deploy two web apps on the same app service using same app service plan.

Your second question was:

If it is not possible, how can I deploy each to separate web apps while encrypting the Travis CI environment variables (like AZURE_WA_USERNAME ) as different values for the branch?

Now we can do this to a degree, you’re going to have to name those environment variables differently, so example being AZURE_WA_USERNAME and AZURE_WA_USERNAME2. So in theory in your before_script hook, you can run this shell script I’ll write out for you, let’s name it var.sh:

if [[ "$TRAVIS_BRANCH" == "master" ]]; then
  export MY_VAR=master
else
  export MY_VAR=not-master
fi

You can now, in your .travis.yml add this:

before_script: source vars.sh

To use hidden environment variables or encrypted variables go to define variables in Repository Settings, make sure you’re logged in, navigate to the repository , choose “Settings” from the cog menu, and click on “Add new variable” in the “Environment Variables” section.

As an alternative to the web interface, you can also use the CLI’s env command.

By default, Travis CI will enforce deploying from your master/main branch.

You can explicitly specify the branch to deploy from with the "on option. So here’s an example:

deploy:
  provider: azure_web_apps
  on: production

Let’s say you had a staging environment as well, it would be the same idea, on would be on: staging so it would look like this:

deploy:
  provider: azure_web_apps
  on: staging

Hope this clears this up and give you a better scope on how to kind of do what you’re asking.

1 Like