18

how can I simulate the build process of Azure Devops pipeline on the local machine before pushing it to branch to test the possible errors.

the solution gets build locally correct with no errors and warnings. also from the VS command line MSBuild builds the solution with no errors but on some push tries the pipeline build throws many errors mostly related to preprocessor defenition and precompiled header.

I wanted to know how can test the same process locally on my machine without pushing to repo.

azure-pipelines.yml
-------------------
pool:
  vmImage: 'vs2017-win2016'

steps:
- task: MSBuild@1
  displayName: 'Build solution'
  inputs:
    platform: 'Win32'
    configuration: 'release'
    solution: 'mysolution.sln'
- task: VSTest@2
  displayName: 'Run Test'
  inputs:
    platform: 'Win32'
    Configuration: 'release'
    testAssemblyVer2: |
     **\*.Test.dll
     !**\*TestAdapter.dll
     !**\obj\**
    runSettingsFile: project.Test/test.runsettings
    codeCoverageEnabled: true 
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123
  • 1
    Possible duplicate of [Is there a tool to validate an Azure DevOps Pipeline locally?](https://stackoverflow.com/questions/53041678/is-there-a-tool-to-validate-an-azure-devops-pipeline-locally) – Alexz S. Aug 22 '19 at 11:46

3 Answers3

8

If you are using a git repsotiory you can create another branch and make a pull request. As long as the pull request is not set to auto complete the code will not get committed to the repository.

If you are using a TFVC respository you can setup a gated build that is configured to fail. The pipeline should be a copy of your original pipeline but add a PowerShell task at the end of the build pipeline that throws a terminating error. Be sure to setup this gated build on a separate branch so it does not block normal development.

Write-Error "Fail here" -ErrorAction 'Stop'

You can now make pull requests or trigger a gated build without the code actually being commited.

You can use AzurePipelinesPS to install an agent on your local machine with the Install-APAgent command if you need another agent.

Dejulia489
  • 1,165
  • 8
  • 14
0

I'm only a few hours into to development with Azure, but I think I found a solution that would work for you. I happen to already have the solution in place. Use gradle, then the default YML just runs gradle and you don't have to worry too much about it after the first run. In the gradle file you could also spin up a docker image if you want and build on that.

gunslingor
  • 1,358
  • 12
  • 34
  • 1
    I don't get anything of it. So, I download gradle and write "use gradle" somewhere and will it magically take the right yaml file, out of the many projects that I have on my hard disk? or will run all the different yamls? Also I can spin up a docker img, for what??? if I already accomplished to run the yaml? And where the result of each step will be shown, on the screen, on a log file? Or maybe you'll get a UI on where you can put breakpoints or what? What will do Gradle with the pipeline result? Will it install in the docker img or will just skip the installation part? – zameb Jul 30 '21 at 17:43
  • 2
    @zameb: I spent some time trying to recall what this was about, lol, long ago now. I believe that the gist of what I was trying to say is: build with gradle or maven locally, have Azure build by calling gradle or maven instead... that way you can build locally as you do remotely without changes. The problem was that Azure has this build file spec file in YML but it can only be run on Azure, which sucks... so build with a better tool, have Azure run that tool via it's YML build spec. – gunslingor Aug 05 '21 at 07:17
0

The issue you have is most likely related to the difference between your local environment and the one on build agent where this YAML pipeline execute the build. Testing it locally (even if it would be possible) will not help as it will be executed in your environment, where you know already that every component required for the successful build are already installed. On the other side on the environment where build agent is running the build there seems to be missed components (or different versions) which cause your build to fail. Try to compare list of installed components and environment variables (like PATH) on your local machine and on build agent - there might be some difference between them.

Sevenate
  • 6,221
  • 3
  • 49
  • 75