Archive

Archive for the ‘Azure’ Category

Azure DevOps | Marketplace tasks | A task is missing error though its installed

October 26, 2022 Leave a comment

In my Azure DevOps organization, I got “Power Platform Build Tools” tools installed from Marketplace.

However none of the ‘Power Platform’ tasks were accessible/visible in my pipelines.

While executing an existing pipelines thrown following exception.

A task is missing. The pipeline references a task called 'microsoft-IsvExpTools.PowerPlatform-BuildTools.tool-installer.PowerPlatformToolInstaller'

Reason and Fix:

  • Using ‘Market place tasks’ in Pipelines was disabled for the Organization.
  • From your Azure DevOps portal, go to Organization Settings -> Pipelines -> Settings
  • Make sure “Disable Marketplace tasks” setting is turned off.

🙂

Azure DevOps | Power Platform Build Tools | WhoAmI | Capture Environment ID

Azure DevOps along with Power Platform Build Tools results a healthy Power Platform ALM.

In this article, I will explain how to use Power Platform WhoAmI task and capture the ‘Environment ID’.

What is PowerPlatformWhoAmi task:

  • Verifies a Power Platform environment service connection by connecting and making a WhoAmI request.
  • This task can be useful to include early in the pipeline, to verify connectivity before processing begins.

YAML snippet of WhoAmi:

Following is the YAML snippet which we would need to include in pipeline.

- task: microsoft-IsvExpTools.PowerPlatform-BuildTools.whoami.PowerPlatformWhoAmi@0
  displayName: 'Power Platform WhoAmI'

  inputs: 
#   Service Principal/client secret (supports MFA)
    authenticationType: PowerPlatformSPN
    PowerPlatformSPN: '{My service connection}'
  • This is how the pipeline YAML looks like.
    • Please note that we must have “PowerPlatformToolInstaller” task before executing “PowerPlatformWhoAmi” task.

Output of PowerPlatformWhoAmi:

  • When you run the pipeline, you would get following outcome for ‘PowerPlatformWhoAmi’.
  • In the output, there is this useful ‘Organization Information’ (Highlighted above) like Org ID, Unique Name, Environment ID etc…

Capture the ‘Environment ID’:

  • As we noticed, in the output of PowerPlatformWhoAmi, we could see useful ‘Organization Information’.
  • PowerPlatformWhoAmi output will be persisted in “BuildTools” Environment Variables.
  • To capture the ‘Environment ID’ use this convention $(BuildTools.EnvironmentId).
  • Use ‘echo’ to test the EnvironmentId as shown below.
  • Once you run the pipeline, you should see the EnvironmentId. As $(BuildTools.EnvironmentId) is an Environment variable, you can use in subsequent pipelines as well.

🙂

[Code Snippet] PowerShell | Azure DevOps | Query Variable Group using API

In Azure DevOps, Variable groups store values and secrets that you might want to be passed into a YAML pipeline or make available across multiple pipelines.

Variable Group is a collection of variables with Name and Value pair.

Below is my variable Group ‘BillingSystemDictionary’ with 3 variables in my DevOps organization ‘RajeevPentyala0011’ and project ‘Demo’ (These details are required in PowerShell script).

In DevOps pipeline scenarios, you may need to fetch the variables under a variable group. Following is the PowerShell script which calls DevOps API and fetch variables by variable group name.

    # Form API authentication Header
    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Authorization", "Bearer $(System.AccessToken)")
    $headers.Add("Content-Type", "application/json")

    # Pass Variable Group Name and read variables
    $variableGroupName = "BillingSystemDictionary"
    # 'projectid' pattern is https://dev.azure.com/{organization_name}/{projectname}
    $projectid = "https://dev.azure.com/RajeevPentyala0011/Demo"

    $variableGroupGetUrl = "$projectid/_apis/distributedtask/variablegroups?groupName=$variableGroupName*&queryOrder=IdDescending&api-version=6.0-preview.2"

    $queryResponseObject = Invoke-RestMethod -Uri $variableGroupGetUrl -Method GET -Headers $headers
 
    # $queryResponseObject will be of type pscustomobject
    # To fetch the variable value of "isactive"
    $variableName = "isactive"
    $variableValue = $queryResponseObject.value.variables.$variableName.value
    Write-Host "$variableName value is $variableValue"

🙂

Categories: CRM, DevOps Tags: , , ,

Azure DevOps | YAML | Could not load type ‘System.Management.Automation.PSSnapIn’

I got the following exception while executing a PowerShell script in my Azure DevOps pipeline step.

Import-Module : Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation, Version=7.2.5.500,

Reason:

  • I used following ‘pwsh‘ task in my YAML file to execute the PowerShell script.
steps:
- pwsh: |
    <My Script>
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  displayName: 'My Task'
  condition: succeeded()
  • For unversed, pwsh is the cross-platform edition of PowerShell built on .NET Core / .NET 5+; by contrast, powershell is the executable name of the legacy Windows PowerShell edition (v5.1-), built on the Windows-only .NET Framework (v4.8-).
  • The issue is ”System.Management.Automation’ is built on .Net Framework and ‘pwsh‘ can’t be used in this case.

Fix:

  • Replace pwsh task with powershell task in YAML file.
steps:
- powershell: |
    <My Script>
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  displayName: 'My Task'
  condition: succeeded()

🙂

Categories: DevOps Tags: ,

Azure DevOps (ADO) | Pipelines | Publish and Access Build Artifacts from Staging Directory

September 23, 2021 Leave a comment

In this article, Lets see how to Publish and Access Build Artifacts using ADO Pipeline.

What are Build Artifacts:

  • Build artifacts are the files generated by your build.
  • In ADO Pipelines, We can use Build.ArtifactStagingDirectory Predefined Variable, on the agent where any artifacts are copied to.

Below are the steps to Publish and Download the Build Artefacts in a ADO Pipeline.

Steps to Publish the Build Artefacts:

  • Lets see how to Publish a file to Build Artifacts folder, using following ‘Power Platform Export Solution’ Task.
  • In the below Task, I am exporting a Solution from CRM Instance and publishing as $(Build.ArtifactStagingDirectory)\$(SolutionName)_managed.zip by using the ‘Solution Output File’ property.
  • In the above the ‘Solution Output File’ property, $(SolutionName) is my custom defined ‘Pipeline Variable’ contains Solution name.
    • ‘ALM_Base’ is my Dynamics Instance Solution name.
  • And $(Build.ArtifactStagingDirectory) is Predefined Variable.
  • Once the pipeline runs successfully, you can download the published artefacts (i.e., Solution folder) as follows.

Steps to Download the Build Artefacts:

  • Go to Pipeline Runs and select the last run.
  • Click on the below highlighted link.
  • Select the folder you want to download.
  • We also have an option to commit these files to Git using ‘Command Line Script’ task.

🙂

Categories: DevOps Tags: , ,

Azure DevOps (ADO) | Pipeline failure | You need the Git ‘GenericContribute’ permission

September 17, 2021 Leave a comment

While pushing the code to Repo using ‘Command Line Script’ task in ADO pipeline, got the following permission issue.

  • Following is the script used in ‘Command Line Script’ task to push the code to main branch.
echo commit all changes
git config user.email "rajeevpentyala@live.com"
git config user.name "Rajeev Pentyala"
git checkout main
git add --all
git commit -m "solution init"

echo push code to new repo
git  -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push origin main

Reason for the issue:

  • Account under which the ADO pipeline running, does not have required permissions to Push the code.

Fix:

  • Go to Settings -> Repositories
  • Under ‘Security’ tab, select the ‘ALM Build Service(User_Name)‘ and grant highlighted privileges.

🙂

Azure DevOps (ADO) | Pipeline failure | Failed to connect to Dataverse

September 16, 2021 Leave a comment

One of my ADO pipelines ‘Power Platform Publish Customizations’ task failed with “Failed to connect to Dataverse” error.

Reason:

  • ‘Power Platform Publish Customizations’ task’s ‘Authentication type’ was selected as ‘Username/password’ which does not have MFA support.
  • MFA (Multi Factor Authentication) was enabled on the Environment, which I was trying to connect from the Pipeline.
  • Since the ‘Power Platform Publish Customizations’ task’s ‘Authentication type’ was selected as ‘Username/password’ which does not support MFA, pipeline could not connect to the Dataverse environment.

Fix:

  • Create an ‘Application User’ by completing App Registration in Azure Active Directory and grant a Security Role.
  • In the ADO pipeline’s ‘Power Platform Publish Customizations’ task, select ‘Authentication type’ as ‘Service Principal’.
  • Make sure the ‘Service Connection’ configured properly with Azure App Registration details (i.e., Tenant ID, Application ID and Client Secret).
    • My connection name is ‘SP_ExpAugust21’ and details are as follows.
  • Save and run the pipeline and it should work now.

🙂

Azure DevOps (ADO) | Pipeline failure | Could not get the latest source version

September 15, 2021 1 comment

I’ve created a new ADO project and configured a Pipeline to export Power Apps solution. While running the Pipeline it failed in immediately with following exception.

The pipeline is not valid. Could not get the latest source version for repository…

Reason:

  • Under the ‘Get sources’ step of the Pipeline, ‘Default branch for manual and scheduled builds’ was auto selected as master.
  • However my existing Branch Name was main.
What is the difference between master and main branches:
  • In ADO, default ‘Branch Name’ used to be master until October 2020. Post that default ‘Branch Name’ changed to main.
  • This Branch name change was not taken affect in Pipelines. New Pipeline defaults the Branch Name to master which is invalid. It has to be main.
  • Refer this ADF product blog for more details.

Fix:

  • In the ‘Get sources’ step of the pipeline, change the Default Branch from master to main.
  • Save and Rerun the pipeline.

🙂

Categories: Azure, CRM Tags: , , ,

Azure DevOps – Unable to ‘Pull’ changes from Visual Studio

I have an Azure DevOps Repo cloned to VS 2017 and ‘Pull’ command was not download and merging the remote repo.

‘Pull’ command update the code in your local repo with the changes from other members of your team. To know more about ‘Pull’ command refer here

Following steps worked as workaround for me.

  • Download and install the Git tools from here
  • From the Visual Studio’s ‘Team Explorer’, go to ‘Sync’.

git_5

  • From ‘Actions’ menu select ‘Open Command Prompt’, which opens up ‘Command Prompt’ where we can run ‘git’ commands.

git_

  • Run the command ‘git pull origin master‘ to fetch and merge the chages of other team members from the default repo ‘Master’. Change the repo name if you want.
  • System would fetch all the code commits by your team members and merge to your local repo.

git_3

  • Run the command again to make sure all the commits were merged to your local repo. You would get ‘Already up to date.’ message as below.

git_4

🙂

Categories: Azure Tags: , ,

Azure DevOps – Getting started by committing a C# console project to Repo and set Policies

February 23, 2019 Leave a comment

Those who are hearing ‘Azure DevOps Services’ for the first time, its formerly known as ‘Visual Studio Team Services (VSTS)’.

And Team Foundation Server (TFS) is now called ‘Azure DevOps Server’.

Below table gives the glimpse of how VSTS features represents in Azure DevOps.

DevOps_14

To know more about Azure DevOps refer this link

In this article, I am going provide the steps to sign-up for ‘Azure DevOps’ and explain how to on board a C# console project.

Pre-Requisite:

  • Microsoft account.
    • You can also use your 30 days trail Dynamics Account to login.
    • If you’re a Visual Studio subscriber and you get Azure DevOps as a benefit, use the Microsoft account associated with your subscription

Sign up for Azure DevOps:

  • Navigate to the VS Portal and click on ‘Get started for free’ as highlighted below

DevOps_15

  • Log in with your ‘Microsoft Account’

DevOps_1

  • Once you complete the registration, you will be redirected to Azure DevOps portal.

DevOps_2

  • A new Organization would have got created by now and to sign in to your organization at any time, go to https://dev.azure.com/{yourorganization}.

Create a New Project:

Once you got your Organization ready, next you need to create a new ‘Project’.

  • On the ‘Create a Project to get started’ form, provide your project name and set the Visibility.
    • Set the Visibility to ‘Private’ if you are working on a customer project which you would not want to expose to Public.
    • ‘Public’ visibility is meant for Open Source projects.

DevOps_17

  • Under ‘Advanced’ tab, I am going with ‘Git’ as my Version Control and ‘Agile’ as Work item process.
  • Your ready with Project and we are close to on board our C# console project.

Repos:

After you create a new Organization and Project, you can begin coding with Git using Repos.

  • Click on ‘Repos’.
  • As a first step in Repos, add ‘README’ or ‘gitignore’, as shown in below.Note that this step is optional but very effective house keeping step.
    • README – You can provide description and objective of your project.
    • gitignore – Will ignore unwanted files to be added to repos.
      • As an example you don’t need components like (Actual nuGet packages, .suo files which comes with VS).
      • I’ve added ‘VisualStudio’ option to the ‘gitignore’ which ignores all unwanted VS files.

DevOps_3

  • Click ‘Initialize’
  • Now you would see 2 files added to your Repo.
  • As mentioned, ‘.gitignore’ contain unwanted file extensions, auto populated. You can add/remove if you want.

DevOps_4

  • ‘README.md’, is a Mark Down file which is a combination of Text and HTML tags. Add your project description.
    • Denotes <H1> tag; ## denotes <H2> tag.

DevOps_5

Clone the Repo to your computer:

To work with a Git repo, you clone it to your computer. Cloning a repo creates a complete local copy of the repo for you to work with.

In this article, I am going to use ‘Visual Studio’ to Clone the Repo. You can also use ‘Command line’ commands using ‘Command Prompt’

  • Click ‘Clone’ and select ‘Clone in Visual Studio’ option under ‘IDE’.

DevOps_6

  • Now Visual Studio opens up and you might need to provide your Microsoft Account credentials.
  • In case if you get ‘Unauthorization’ error, you can connect as below from your VS ‘Team Explorer’.

DevOps_16

  • Once you complete the clone, the 2 files (i.e., .gitignore, README.md) would synced to your computer folder.

Commit C# Console Project to Repo:

Once you Cloned of your DevOps ‘Project’ to your local computer folder, below are the steps to add a new C# console project to Repo.

  • Create a new C# console application project and save at the same folder location where you cloned your Azure Project.
  • Now you would see the Console project in your Visual Studio.
  • You would notice #5 in the Visual Studio footer, which denotes 5 new files are new and not synced to your Repo.

DevOps_7

  • You need to commit the files to sync with your Repo.
  • Click on #5 icon and provide mandatory ‘Commit comments’ and choose ‘Commit All and Push’ option to commit and upload the C# console project to Repo.

DevOps_8

  • Now, go to your Azure DevOps portal and you would see your C# console project.

DevOps_9

  • You can also Edit the class files directly from DevOps portal.

Branch Policies:

As you would have noticed, Visual Studio did not allow me to commit the files until I provide the ‘Comments’. Its a policy implied by default by DevOps.

Lets see how to configure the policies.

  • Once you create a new Project, DevOps will create a default ‘master’ branch.
    • Refer article for more details on ‘Branch’.
  • Under Repos->Branches, select ‘Branch Policies’ from the Branch menu.

DevOps_10

  • You can configure appropriate policies mainly to improve the code quality.
    • Refer link to know more details on Policies.

DevOps_11

Grant access on Project to Users:

For every new project you add to DevOps Organization, a new Team gets created with naming convention {Project Name} Team.

  • Click on ‘Teams’ tab as shown in screen below and pick your Project team.
  • ‘+Add’ to add users

DevOps_13.PNG

  • Refer this link to know more details on managing Teams.

Service Hooks:

  • Service hooks let you run tasks on other services when events happen in your Azure DevOps Services projects.
  • For example, you can create an entry in Azure Service Bus when there Code commit happens.

DevOps_12

  • Refer this article for more details on ‘Service Hooks’

In my next article I will share the details on how to implement Build activities using Pipelines

🙂