How to solve this Invalid/Missing environment variable error while build

Biz Admin 51 Reputation points
2023-09-26T09:58:21.3733333+00:00

Getting Error: Invalid/Missing environment variable: "MONGODB_URL"

while deploying nextjs mongodb app in azure. i have added env variables on configuration - Application settings, but still deployment getting failed.

User's image

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,631 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,757 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
925 questions
{count} votes

Accepted answer
  1. Ryan Hill 28,106 Reputation points Microsoft Employee
    2023-09-27T01:16:27.5166667+00:00

    Hey @Biz Admin

    From what I'm seeing, this is during the actions/checkout@v2 build task. I think you're checking for this setting in the pipeline, and it isn't found as an environment variable. You really don't need to have/refer to/set MONGODB_URL as part of the pipeline, so I would remove it. Reason being, it's a setting your application will retrieve at runtime. However, if you want to set the app setting from the pipeline, you can do something like

          - name: Set App Service App Setting
            uses: Azure/appservice-settings@v1
            with:
              app-name: your-app-name
              app-setting-json: |
                {
                  "MONGODB_URL": "AppSettingValue"
                }
    

    or

    - name: Log in to Azure CLI
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_SERVICE_PRINCIPAL }}
    
    - name: Configure deployment and runtime settings on the webapp
      run: |
        az configure --defaults ${{ env.RESOURCE_GROUP }}
        az webapp config appsettings --name ${{ env.WEBAPP_NAME }} --settings \
            MONGODB_URL=${{ env.MongoDb }}
    

    Assuming your created MongoDb as an environment variable.


2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Biz Admin 51 Reputation points
    2023-09-29T03:26:17.48+00:00

    Issue solved -

    issue solved by adding this env variable with build run, also don't forget to add this environment variables on GitHub secrets.

    issue_solve-44566

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.