Automating Power Platform solution deployment with GitHub Actions

Hello friends! I’m back with another post on GitHub actions, where in this post, we’ll take a look at how to automate a solution deployment! If you didn’t check out yesterdays post on an introduction to GitHub Actions for working with Power Platform, including… READ MORE [https://lewisdoes.dev/b
blue and white sky with stars
Photo by Rafael Cerqueira on Pexels.com
In: Low Code Lewis Content 🚀

Hello friends! I’m back with another post on GitHub actions, where in this post, we’ll take a look at how to automate a solution deployment! If you didn’t check out yesterdays post on an introduction to GitHub Actions for working with Power Platform, including how to use secrets in GitHub, check out the post below…

New workflow

So lets jump into a repository in GitHub and create a new actions workflow!

Start by adding the following into your yml file.

name: export-and-import-solution
# Export solution from DEV environment and import to test

on:
  workflow_dispatch:
    inputs:
      # Change this value
      solution_name:
        description: 'name of the solution to worked on from Power Platform'
        required: true
        default: ALMLab
       #Do Not change these values
      solution_exported_folder:
        description: 'folder name for staging the exported solution *do not change*'
        required: true
        default: out/exported/

In the above yml we gave our workflow a name, set the trigger for the workflow and then added some parameters.

Now we will add some connection variables using the following:

env:
#edit your values here
  DEV_ENVIRONMENT_URL: ''
  DEV_CLIENT_ID: ''
  DEV_TENANT_ID: ''
  TEST_ENVIRONMENT_URL: ''
  TEST_CLIENT_ID: ''
  TEST_TENANT_ID: ''
permissions:
  contents: write

In the above replace all of the environment values for each property. So enter your dev environment values and test environment values. If you’re deploying to a build or prod environment feel free to change the names of the test properties.

Now we will add our job and its tasks with the following code.

jobs:
  export-from-dev:
    runs-on: windows-latest
    # or you can say runs-on: ubuntu-latest
    env:
      RUNNER_DEBUG: 1

    steps:
    - uses: actions/checkout@v2
      with:
        lfs: true

    - name: export-solution action
      uses: microsoft/powerplatform-actions/export-solution@v0
      with:
        environment-url: ${{env.DEV_ENVIRONMENT_URL}}
        app-id: ${{env.DEV_CLIENT_ID}}
        client-secret: ${{ secrets.Dev_Environment_Application_Secret }}
        tenant-id: ${{env.DEV_TENANT_ID}}
        solution-name: ${{ github.event.inputs.solution_name }}
        solution-output-file: ${{ github.event.inputs.solution_exported_folder}}/${{ github.event.inputs.solution_name }}.zip

    - name: Import solution to test env
      uses: microsoft/powerplatform-actions/import-solution@v0
      with:
        environment-url: ${{env.TEST_ENVIRONMENT_URL}}
        app-id: ${{env.TEST_CLIENT_ID}}
        client-secret: ${{ secrets.Test_Environment_Application_Secret }}
        tenant-id: ${{env.TEST_TENANT_ID}}
        solution-file: ${{ github.event.inputs.solution_exported_folder}}/${{ github.event.inputs.solution_name }}.zip
        force-overwrite: true
        publish-changes: true

In the above yml, replace the values following secrets. in each part of the code with the relevant secret you need to use to connect to that environment. So in the export solution action, reference your source environment application secret and then in the import solution reference your target environment application secret.

You need to have added your secrets in the repository settings first, which you’ll find help for in this post…

Save and test

Now select that green commit changes button and head to the actions tab again in your repository. Now select to run the workflow and provide a name of a solution which you have in the source environment that you want to import to the target and simply select run workflow.

Now I’ll take a look at my workflow run and as you can see my solution has been deployed!

Upcoming content 📝

Make sure you’re subscribed so you don’t miss my upcoming content on working with GitHub actions to achieve CI/CD automation scenarios for working with Power Platform! I’ve still got a bunch of posts to come covering all sorts of workflows you can achieve using the actions for Power Platform! 📩

Subscribe
Written by
Lewis Baybutt
Microsoft Business Applications MVP • Power Platform Consultant • Blogger • Community Contributor • #CommunityRocks • #SharingIsCaring
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to LewisDoesDev.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.