Power Platform with CICD via Git Action

Tutorial: Automate solution deployment using GitHub Actions for Microsoft Power Platform (Preview)

 

 

[This topic is pre-release documentation and is subject to change.]

In this tutorial, you will learn how to:

  • Create a new GitHub repository
  • Create two GitHub workflows using GitHub Actions for Microsoft Power Platform

The workflows can automatically export your app (as an unmanaged solution) from a development environment, generate a build artifact (managed solution), and deploy the app into your production environment. This tutorial uses the ALMLab solution you built and the environments you set up in previous tutorials.

Related tutorials: Get started, and Build a model-driven app.

Create a GitHub Account

  1. Go to https://github.com and click Sign up or Start a free trial (or sign in if you have an existing account).

    Power Platform with CICD via Git Action

  2. After you have created your account, create a repository by selecting Create repository or New.

    Power Platform with CICD via Git Action

    You might see the following alternative landing screen:

    Power Platform with CICD via Git Action

  3. Create your new repository and name it ‘poweractionslab’. Make sure you select Add a README file to initiate the repo and choose Create repository.

    Power Platform with CICD via Git Action

Create a new secret to be used by GitHub Actions

  1. Navigate to the repo from the link in the import wizard and select Settings, navigate to Secrets, and then click New secret.

    Power Platform with CICD via Git Action

  2. On the secrets page, name the secret ‘password’. Type the password for the username you are using to connect to Power Platform into the Value field and select Add secret. The password will be referenced in the YML files used to define the GitHub workflows later in this lab.

    Power Platform with CICD via Git Action

     Note

    In the preview release, only username + password is supported. Support for service principals (application user) will be available later in Fall 2020.

    The password is now securely stored as a GitHub secret.

    Power Platform with CICD via Git Action

Create a workflow to export and unpack the solution file to a new branch

  1. Select Actions and then set up a workflow yourself.

    Power Platform with CICD via Git Action

    This will start a new YML file with a basic workflow to help you get started with GitHub Actions.

    Power Platform with CICD via Git Action

  2. Delete the pre-created content, paste the content from the export-and-branch-solution.yml file, and then rename the file to ‘export-and-branch-solution’.yml.

    Power Platform with CICD via Git Action

  3. Update <ENVIRONMENTURL> with the URL for the development environment you want to export from (for example: https://poweractionsdev.crm.dynamics.com).

  4. Update <USERNAME> with the username you are using to connect to the environment.

  5. You are now ready to commit your changes. Select Start commit, type Create export yml in the title field, and then add a description (optional). Next, click Commit new file.

    Power Platform with CICD via Git Action

Congratulations, you have just created your first GitHub workflow using the following actions:

  • Who Am I: Ensures that you can successfully connect to the environment you are exporting from.
  • Export Solution: Exports the solution file from your development environment.
  • Unpack Solution: The solution file that is exported from the server is a compressed (zip) file with consolidated configuration files. These initial files are not suitable for source code management as they are not structured to make it feasible for source code management systems to properly do differencing on the files and capture the changes you want to commit to source control. You need to ‘unpack’ the solution files to make them suitable for source control storage and processing.
  • Branch Solution: Creates a new branch to store the exported solution.

Test the export and unpack workflow

  1. Next, test that the workflow runs. Navigate to Actions, Run workflow, and choose Run workflow.

    Power Platform with CICD via Git Action

  2. After 5–10 seconds the workflow will start, and you can select the running workflow to monitor progress.

    Power Platform with CICD via Git Action

    Power Platform with CICD via Git Action

  3. After the workflow has completed, validate that a new branch has been created with the solution unpacked to the solutions/ALMLab folder. Select Code and then Branches.

    Power Platform with CICD via Git Action

  4. Select the branch that was created by the action.

    Power Platform with CICD via Git Action

  5. Validate that the solutions/ALMLab folder has been created in the new branch and then create a pull request to merge the changes into the main branch. Click Pull request.

    Power Platform with CICD via Git Action

  6. In the Open a pull request form, add a title and description (optional), and then choose Create pull request.

    Power Platform with CICD via Git Action

  7. You are then presented with the pull request summary. Confirm that the branch has no conflicts with the main branch and that the changes can be merged into the main branch automatically. Select Squash and merge and then Confirm squash and merge.

    Power Platform with CICD via Git Action

  8. Navigate back to the main branch and validate the solution is now available there as well.

Create a workflow to generate a build artifact and import to production

In this section, we will create an additional workflow that:

  • Creates a managed solution and publishes it as a GitHub artifact
  • Imports the build artifact into the production environment
  1. Navigate to Actions and select New workflow.

    Power Platform with CICD via Git Action

  2. Chose setup a workflow yourself.

    Power Platform with CICD via Git Action

  3. Rename the title of the workflow to ‘release-solution-to-prod’ and copy the content from the release-solution-to-prod.yml file and paste it into the Edit new file screen.

    Power Platform with CICD via Git Action

  4. Update the following variables in the new workflow file:

    • Update <BUILDENVIRONMENTURL> with the URL for the build environment you are using to generate the managed solution. For example: https://poweractionsbuild.crm.dynamics.com.
    • Update <PRODUCTIONENVIRONMENTURL> with the URL for the production environment you are deploying to. For example: https://poweractionsbuild.crm.dynamics.com.
    • Update <USERNAME> with the username you are using to connect to the environments.
  5. Commit the changes. Choose Start commit and then add a title and description (optional). Next, select Commit new file.

Power Platform with CICD via Git Action

Test the release to production workflow

You are now ready to test the last workflow. This workflow is triggered when a new release is deployed to production.

  1. Navigate to Releases.

    Power Platform with CICD via Git Action

  2. Select Draft a new release.

    Power Platform with CICD via Git Action

  3. Add a release tag, a title, and choose Publish release.

    Power Platform with CICD via Git Action

  4. Select Actions to view the running workflow.

    Power Platform with CICD via Git Action

  5. Choose the running workflow to view the actions as they run.

    Power Platform with CICD via Git Action

  6. Wait for each action to complete.

    Power Platform with CICD via Git Action

  7. After the workflow has completed, log into your production environment and validate that the solution has been deployed as a managed solution.

Deploy the update and review changes before production release

We will now test the end-to-end process and then see how we can view and validate changes to an app before it is deployed to production.

  1. Navigate to the ALMLab solution in your development environment and choose Edit.

    Power Platform with CICD via Git Action

  2. Select and view the Time off Request entity.

    Power Platform with CICD via Git Action

  3. Select Add field and create the new field as shown in the figure below.

    Power Platform with CICD via Git Action

  4. Select Done.

  5. Navigate back to your GitHub repo to Actions, choose Run workflow, and select the Run workflow button.

    Power Platform with CICD via Git Action

  6. After 5–10 seconds, the workflow will start and you can click on the running workflow to monitor its progress.

    Power Platform with CICD via Git Action

    Power Platform with CICD via Git Action

  7. After the workflow completes, navigate to the new branch by selecting Code and then Branches.

    Power Platform with CICD via Git Action

  8. Select the branch that was created by the workflow and choose New pull request.

    Power Platform with CICD via Git Action

  9. Select Pull request on the next page.

    Power Platform with CICD via Git Action

  10. Add a title and then choose Create pull request.

    Power Platform with CICD via Git Action

  11. On the pull request page, select the Files changed tab.

    Power Platform with CICD via Git Action

  12. Notice that the changes to the solution are highlighted in green to indicate that this section of the file was added when compared to the same file in the main branch.

    Power Platform with CICD via Git Action

  13. Navigate back to the pull request. Select Pull requests and then select the pull request previously created.

    Power Platform with CICD via Git Action

  14. On the Pull request page, select Squash and merge to merge the updated solution file into your main branch.

    Power Platform with CICD via Git Action

  15. Follow the steps in the Test the release to production workflow section to create a new release and validate that the updated solution has been deployed to your production environment.

Congratulations, you have successfully setup a sample CI/CD workflow using GitHub actions!

上一篇:CICD构建实验


下一篇:Gitlab+Jenkins+K8s集群+Kuboard+Harbor实现自动化CICD