Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Environment Variables Mapping - Azure DevOps Pipelines - Power platform

Like (1) ShareShare
ReportReport
Posted on 3 Jan 2025 10:31:56 by 6
Hi
 
Can someone explain how to map environment variables in solution while using Azure devOps pipeline.
This is document related to it. That I raised a question previously.
 
 
Categories:
  • Suggested answer
    VASANTH KUMAR BALMADI Profile Picture
    266 on 03 Jan 2025 at 14:19:55
    Environment Variables Mapping - Azure DevOps Pipelines - Power platform
    Hi,
     
    Mapping environment variables in a Power Platform solution using an Azure DevOps pipeline involves defining and substituting variables during the deployment process. Here's a step-by-step explanation based on the context and the linked community forum thread:

    Overview

    Environment variables in Power Platform solutions are placeholders for values that vary across environments (e.g., development, staging, production). Using Azure DevOps, you can manage these variables dynamically and inject the appropriate values during deployment.

    Step-by-Step Process

    1. Define Environment Variables in Power Platform Solution

    • Create Variables:
      • Open your solution in the Power Platform environment.
      • Go to Environment Variables under the Solution Components.
      • Add new environment variables with a Display Name, Schema Name, and optional Default Value or Current Value.
    • Example Variable:
      • Display Name: API Endpoint
      • Schema Name: new_APIEndpoint

    2. Export the Solution

    • Export the solution from your source environment as unmanaged or managed.
    • Save the .zip file and ensure the environment variables are part of the solution.

    3. Setup Azure DevOps Pipeline

    • Create a Pipeline:
      • Use the Azure DevOps pipeline YAML or Classic Editor.
    • Install Power Platform Build Tools:
      • Add the Power Platform Build Tools extension from the Azure DevOps marketplace to your organization.

    4. Add Tasks for Deployment

    • 1. Power Platform Export Solution:

      • Task: Export Solution
      • Parameters: Export the solution from the source environment.
    • 2. Unpack Solution:

      • Task: Unpack Solution
      • Parameters: Unpack the .zip solution into source control.
    • 3. Update Environment Variables:

      • Use a script task (e.g., PowerShell) to replace placeholder values in the unpacked solution files with environment-specific values.
      • Example of environment variable mapping in YAML:
        - task: PowerShell@2
        inputs:
        targetType: 'inline'
        script: |
        Write-Host "Updating environment variables..."
        $solutionFolder = "$(Build.SourcesDirectory)/Solutions"
        $envVariableFile = "$solutionFolder/EnvironmentVariables.json"
        (Get-Content $envVariableFile) -replace '<<APIEndpoint>>', 'https://prod.api.example.com' | Set-Content $envVariableFile
    • 4. Pack Solution:

      • Task: Pack Solution
      • Parameters: Re-pack the updated solution back into a .zip.
    • 5. Import Solution:

      • Task: Import Solution
      • Parameters: Import the updated solution into the target environment.

    5. Set Up Variable Groups in Azure DevOps

    • Create Variable Groups:
      • Define environment-specific variables in Azure DevOps (e.g., Dev, Staging, Production).
    • Example Variables:
      • APIEndpoint = https://dev.api.example.com (for Dev)
      • APIEndpoint = https://prod.api.example.com (for Prod)
    • Link the variable group to the pipeline stages.

    6. Test the Pipeline

    • Trigger the pipeline and validate:
      • The appropriate environment variables are substituted.
      • The solution imports successfully with the correct values.

    7. Monitor and Debug

    • Use logs from the pipeline tasks to ensure values are correctly mapped and the solution deploys without errors.

    Key Considerations

    • Consistency: Ensure schema names for environment variables match between environments.
    • Security: Mask sensitive variables (e.g., API keys) using Azure DevOps variable secrets.
    • Pipeline Stages: Use different stages for each environment to ensure safe deployment.
    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 98 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard
Loading started