MSBA-343 · Lesson 8 of 12 · 19 min
Source control and builds
▶ Video coming soon A video version of this lesson is on the way.
Kiri's fourth checklist line read: every package that reaches UAT or production is built by the pipeline from a reviewed commit. It sounded like a formality. Desmond explained to Prudence why it was not. In the old ERP, Cobalt Ridge's customizations had been compiled on a developer's machine and copied to the server by hand. Twice in five years, a change that existed only on one laptop had reached production, and once a fix had been lost when the laptop was replaced. Source control and automated builds are how a team proves what is running and how it got there.
Prudence had used Git in the first clinic series, committing to feature branches in the Cobalt Ridge repository in Azure Repos and opening pull requests. This session went further: how the repository is organized, how branches map to environments, what the build pipeline does, and how the same practices work on GitHub, which the MB-500 outline lists alongside Azure DevOps.
What goes into the repository
X++ metadata is stored as XML files, one per element, in a folder structure under the package and model: a folder for classes, one for tables, one for forms and so on. In the unified developer experience, the developer's custom metadata lives in a local folder configured in Visual Studio, and that folder is what goes into source control. Microsoft's packages, which developers download as part of the finance and operations assets, do not go into the repository; they are references, restored or downloaded for each version.
Cobalt Ridge's repository had a simple layout. The Metadata folder held the CobaltRidgeCustom and CobaltRidgeCustomTests packages. A Projects folder held the Visual Studio projects developers used to group elements. A Pipelines folder held the build and release definitions as YAML files. A docs folder held the extension point list and the release notes. A .gitignore file excluded build output, binaries and Visual Studio's local settings, so that only source went into commits.
Branches and environments
Desmond used a branching model that was simple enough to follow under pressure. The main branch always held code that had passed review and build validation. Developers worked on short-lived feature branches, named after the work item, such as feature/2214-alert-queue-setbased, and merged them into main through pull requests. When a release was ready for UAT, a release branch was cut from main, such as release/2027.01, and only fixes for that release were merged into it. Fixes made on a release branch were merged back into main, so they were not lost.
Branch policies in Azure Repos enforced the rules. Pull requests into main and release branches needed at least one reviewer who was not the author, a linked work item, all comments resolved and a successful build validation. Nobody, including Desmond, could push directly to main. Thandeka asked to be an optional reviewer on any pull request that touched security objects, and the policy added her automatically when a changed file's path contained AxSecurity.
| Branch | Purpose | Builds go to |
|---|---|---|
| feature/... | One change, short-lived | Build validation only |
| main | Reviewed, integrated code | Nightly build; CONFIG after approval |
| release/2027.01 | The code for one release, fixes only | UAT, then production |
| hotfix/... | An urgent production fix from the release branch | UAT, then production, merged back to main |
Pull requests and reviews
A pull request at Cobalt Ridge was more than a merge button. Its template asked the author to list new or changed entry points and the privileges that cover them, new indexes and the trace that justified them, any skip methods with the reason, tests added or changed, and whether the change touched a form that RSAT recordings use. The reviewer read the diff in Azure Repos, which shows XML metadata changes line by line. Desmond showed Prudence how to read a form's XML diff: most changes were small, such as a new control or a changed property, and a large diff usually meant the designer had reordered elements, which was worth a question.
Merge conflicts in metadata are less common than in ordinary code because each element is its own file, but they happen when two developers change the same element. The MB-500 outline expects developers to compare code and resolve version conflicts. Desmond's advice was to resolve them in Visual Studio's merge tool, which understands the file, then build and run the affected tests before completing the merge. A conflict resolved without building was a conflict resolved by guessing.
The build pipeline
The build pipeline turns source into a package. Cobalt Ridge's pipeline ran on Microsoft-hosted agents in Azure Pipelines, which meant no build virtual machine to maintain. A hosted agent does not have the X++ compiler installed, so the pipeline restores it and Microsoft's reference packages from NuGet packages for the target version. Microsoft publishes these packages for each version, including the Compiler Tools package that supplies the X++ compiler, and the pipeline restores the versions that match the environment Cobalt Ridge was building for. Microsoft's documentation notes a quirk: the NuGet version used by the build task must be 3.3.0 or earlier, because later versions use semantic versioning in a way that breaks the task.
The pipeline then compiles the CobaltRidgeCustom and CobaltRidgeCustomTests models with MSBuild against those references, runs best practice checks, and creates a deployable package. The packaging task comes from the Dynamics 365 finance and operations Tools extension, which must be installed in the Azure DevOps organization. Its Create Deployable Package task takes the path to the X++ tools, the location of the compiled binaries, a search pattern for which binaries to include, and the file name for the package. Cobalt Ridge's search pattern included everything and then excluded modules whose names end in Tests, so test code never reached a package.
# build-main.yml (sketch)
trigger:
branches:
include: [ main, release/* ]
pool:
vmImage: windows-latest
steps:
- task: NuGetToolInstaller@1
inputs:
versionSpec: '3.3.0'
- script: nuget restore Pipelines/packages.config -PackagesDirectory NuGets
displayName: Restore compiler tools and reference packages
- task: VSBuild@1
displayName: Build CobaltRidgeCustom and tests
inputs:
solution: Pipelines/Build/Build.sln
- task: XppCreatePackage@2
displayName: Create deployable package
inputs:
XppToolsPath: NuGets/Microsoft.Dynamics.AX.Platform.CompilerPackage
XppBinariesPath: Bin
XppBinariesSearch: |
*
!*Tests
DeployablePackagePath: Out/CobaltRidgeCustom.zip
CreateCloudPackage: true
- task: PublishPipelineArtifact@1
inputs:
targetPath: Out
artifact: packagesTwo package formats
A newer version of the Create Deployable Package task can produce two formats. The Lifecycle Services format is the traditional deployable package, uploaded to the Lifecycle Services asset library and applied to environments managed there. The Power Platform unified package format is used to deploy to unified environments managed in the Power Platform admin center. The task creates the Lifecycle Services package by default and can create the unified package as well when the Create Power Platform Unified Package option is selected with the platform and application versions. Cobalt Ridge's CONFIG and UAT sandboxes were still managed through Lifecycle Services, while developer environments were unified, so the pipeline produced both. Lesson 9 follows both packages into environments.
Versions and traceability
Every build had a number, and Desmond wanted that number to be visible everywhere. The pipeline stamped the build number into the model's version, using a model version task from the same extension, so that the version shown for CobaltRidgeCustom in an environment matched a build in Azure Pipelines. From the build, anyone could follow links to the commits, the pull requests and the work items it contained. When Thandeka asked which change had added the void privilege, Prudence could find it in under a minute: environment version, build, pull request, work item.
Build validation on pull requests used the same pipeline with a flag that skipped packaging, to keep it fast. It compiled the change, ran the fast unit tests and failed the pull request if either failed. The nightly build of main ran everything, including the slower tests, and published packages.
Best practice checks
The X++ compiler reports best practice warnings in addition to errors: missing labels, unused variables, fields without help text, display methods without the right modifiers, and many more. The MB-500 outline expects developers to resolve best practice warnings. Cobalt Ridge's rule was that new code introduced no new warnings. The build reported the count, and a pull request that raised it needed a comment explaining each exception. Desmond did not chase every historic warning; he chased new ones, which kept the count falling without a cleanup project.
The same practices on GitHub
Some partners and customers keep finance and operations code on GitHub instead of Azure Repos, and the MB-500 outline mentions both. The practices transfer directly. Repositories hold the same metadata folders; branch protection rules or rulesets replace Azure Repos branch policies; pull requests with required reviews and status checks replace pull request policies; and GitHub Actions workflows can run the build, either by calling the same tools on a Windows runner or by triggering an Azure Pipelines build. Work items might live in GitHub Issues or remain in Azure Boards, linked from commits. The release side, which deploys packages to environments, can run in either system.
Desmond's view was that the tool mattered less than three habits: nothing reaches a shared environment except through a reviewed pull request; every package comes from a pipeline, not a laptop; and every environment's version can be traced back to commits.
Day-to-day work with Git
Prudence's daily routine had settled into a pattern. In the morning she pulled main and created a feature branch for the work item. She made changes in Visual Studio, building and deploying to her developer environment as often as needed. She committed small, coherent changes with messages that said why, not only what, such as Index certificate lookup by purchase line to fix slow receipts, and pushed the branch so the work was never only on her laptop. When the change was ready, she opened a pull request, answered review comments with further commits, and let Azure Repos complete the merge once policies passed. The feature branch was then deleted.
The MB-500 outline speaks of creating, checking out, reviewing and checking in code. Those words come from the older centralized version control that finance and operations projects once used, where a file was checked out to one developer and checked in when done. In Git, nobody locks a file; the equivalent steps are creating a branch, committing, pushing and merging through a pull request. Desmond made sure Prudence could explain both vocabularies, because exam questions and older documentation still use the older words.
Keeping secrets out of the repository
Pipelines need credentials: a service connection to the Power Platform environments, access to the NuGet feed, perhaps a certificate for tests. None of these belong in the repository. Azure DevOps stores them as service connections and secret variables, and pipelines refer to them by name. Desmond enabled secret scanning on the repository as a safety net and asked Prudence to check every pull request diff for anything that looked like a key or password before asking for review. If a secret were ever committed, the rule was to treat it as leaked: revoke and replace it first, then clean the history.
When the build breaks
A broken build of main stops everyone, because nobody can be sure their changes integrate. Cobalt Ridge's rule was that whoever broke main fixed it or reverted their change within the hour. The pipeline posted failures to the team channel with a link to the log, and the most common causes were predictable: a reference package version that did not match the target environment, an element that compiled locally because of an uncommitted file, and a best practice error that had been a warning on the developer's machine.
Prudence asked whether a broken build was worth an hour of everyone's attention. Desmond's answer was that the cost of a broken main grows every hour it stays broken: each developer who pulls it inherits the problem, each pull request's build validation fails for a reason unrelated to its change, and the nightly package that CONFIG depends on is not produced. An hour spent by one person is cheaper than a morning lost by four, and the habit of fixing main at once keeps the team trusting the pipeline.
Worked problem
Tracing a production change to its source
After go-live, Thandeka asks which change made the void button available to the warranty administrator role, and who approved it. How should Prudence answer?
Show solution
- Read the CobaltRidgeCustom model version shown in the production environment, which matches a build number.
- Open that build in Azure Pipelines and list the commits and pull requests it contains.
- Search the pull requests for changes to the CRPumpWarrantyVoid privilege or duty files under AxSecurity.
- Open the pull request to see the author, the reviewers, Thandeka's review and the linked work item.
- Report the work item, the approval and the release it shipped in.
Answer: Because every package comes from a pipeline that stamps its build number into the model version, the path from production back to the reviewed change is a few clicks.
Common mistakes
MistakeCommitting build output and binaries to the repository.
InsteadCommit only source metadata and exclude build output with .gitignore.
MistakeBuilding packages on a developer machine for UAT.
InsteadBuild every shared package in the pipeline from a reviewed commit.
MistakeResolving a metadata merge conflict without building.
InsteadResolve, build and run the affected tests before completing the merge.
MistakeIncluding test models in deployable packages.
InsteadExclude modules ending in Tests with the package search pattern.
Summary and key terms
- X++ metadata is stored as XML files per element; only custom packages go into source control.
- Short-lived feature branches, a protected main branch and release branches map code to environments.
- Pull requests with required reviewers, linked work items and build validation enforce quality.
- Hosted build agents restore the compiler and references from NuGet; Create Deployable Package produces Lifecycle Services and unified packages.
- Model versions stamped from build numbers make every environment traceable to commits, on Azure DevOps or GitHub.
- Branch policy
- A rule in Azure Repos that protects a branch, such as required reviewers and build validation.
- Build validation
- A build that runs automatically on a pull request and must succeed before merging.
- Deployable package
- A file containing compiled models that can be applied to an environment.
- Unified package
- The package format used to deploy to environments managed in the Power Platform admin center.
- Best practice check
- A compiler rule that reports code or metadata that does not follow recommended practice.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Which Azure DevOps extension provides the Create Deployable Package task?
Show answer
Dynamics 365 finance and operations Tools.
Which NuGet version does Microsoft say the packaging task needs?
Show answer
3.3.0 or earlier.
How did Cobalt Ridge keep test code out of packages?
Show answer
The binaries search pattern excluded modules whose names end in Tests.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.