Azure Devops - Build Automation - azure-devops

I have a Azure DevOps Git Repo with many solutions in it, and are starting down the path of build, test, deploy automation.
I figured out how to run a rebuild if any file changes in the repo.
However, since the repo has many solutions in it, I only want to run a given rebuild of a solution if a specific subfolder changes.
Is that possible, and if so, how do I accomplish this?

you can use path based trigger filters (i'm fairly certain they are only supported in yaml builds). example:
trigger:
paths:
include:
- folder1/*
- folder2/somefile
- etc
Reading:
https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema
https://learn.microsoft.com/en-us/azure/devops/pipelines/create-first-pipeline?view=azure-devops&tabs=tfs-2018-2

Related

How can I use a Visual Studio solution (.sln) to determine the path filters for an Azure Pipelines trigger?

For my application I have a solution file (.sln) containing the "main" application assembly (c:\src\app) and the three internal libraries that are used: c:\src\lib\Lib1, c:\src\lib\Lib2, and c:\src\lib\Lib3.
I also have a c:\src\azure-pipelines.yml file that builds (and tests and publishes) my solution file. The pipeline's triggers are branch triggers (e.g. main and patch), with a set of path filters, one for each assembly:
trigger:
branches:
include:
- main
- patch/*
paths:
include:
- app/*
- lib/Lib1/*
- lib/Lib2/*
- lib/Lib3/*
I know that more lib/ projects will be created and added to my .sln over time, and I want changes to those libraries to trigger my pipeline, so I know that I'll need to add to both the .sln and the .yml, and ideally at the same time.
But the solution already lists the project folders, which is exactly the set of paths that I want to trigger on!
How can I take advantage of this? I'd like to do something, maybe during a local (workstation) build, to automate updating the paths/include list based on the solution contents. At the very least getting the .yml to show up in my source control as having changed would be useful.

How to trigger an Azure DevOps pipeline on a specific folder in any workspace in a repository

I have a pipeline that I want to run on any changes to files in src/*/foo/bar in my repository.
trigger:
branches:
include:
- main
paths:
include:
- src/*/foo/bar
Unfortunately, the * does not work for this purpose. It will work if I hardcode the path (like src/workspace/foo/bar).
How can I get it to run the way I want? Should I use */foo/bar?
Apparently, the only problem was a missing "/" at the beginning of the trigger path. It's working now automatically with that added (and using "**" for the recursive search).
The path spec does allow wildcards, see the documentation.
Unfortunately, azure devops paths specification does not include wildcard support.
One trick you could do is to have a pipeline that triggers on src/, and have that pipeline trigger another pipeline if the changes are in the specific paths you're interested in. You'll have to keep track of the last commit that you looked at, so you can do it incrementally on each run. This is heavy weight, and not trivial. I don't know of any other way though.

azure devops triggers trouble understanding

I've got a problem where I cannot get my pipeline to run when I want it to.
Background
I have a repo in GitHub, and I'm running my pipelines in ADO.
I have two branch - main branch, feature branch.
I want a pull request to trigger a pipeline called "pull-request" when I make a pull request in github.com. I want the pipeline to exclude any changes that happen to a file called azure-pipeline-pull-request.yml (which is the pipeline file).
I don't want it to run any other time.
I have tried many different combos in the yml file, but I cannot get the pipeline to run when a PR happens.
This is the code at the top of the YAML file.
trigger:
branches:
include:
- main
paths:
exclude:
- azure-pipelines-pull-request.yml
pr:
branches:
include:
- main
paths:
exclude:
- azure-pipelines-pull-request.yml
I've tried it without the trigger section. I could do with some help in explaining what is happening.
I tried your code and successfully triggered the pipeline to run. So some other reasons caused the pipeline not running automatically instead of your script.
There are several possible reasons for the issue. Click I just created a new YAML pipeline with CI/PR triggers, but the pipeline is not being triggered. for detailed information and steps. Here is a brief overview of the content of the document:
Go to "Triggers" in UI. Turn off the "Override the YAML trigger from here" setting.
Check whether your Github repository is connected to multiple Azure DevOps organizations. If so, remove the service connection and re-establish it.
Check whether there is a failure in Webhooks in Github.
Make sure that the YAML file in the correct branch has the necessary CI or PR configuration.
Did you use templates for your YAML file? If so, make sure that your triggers are defined in the main YAML file.

How to setup GitHub workflow CI / build to build each directory when something gets pushed?

I've added GitHub Actions Workflow to my repo and tried to configure it but failed. Checked few websites but couldn't find a clear answer. How can one configure its Workflow so that C++ CI/Build would build each directory separately whenever I push something to the repository?
Note: My repo contains several folders of source code and each has different project/code snippets.
You can filter each workflow to only run when commits affect files in a certain path:
https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpaths
on:
push:
paths:
- 'sub-project/**'
- '!sub-project/docs/**'

Azure DevOps Server 2019-TFVC Prevent build from occurring if changes are only in certain folder

I've recently set up an Azure DevOps Server 2019 on our local servers using TFVC for our source control. Our branch is structured as follows:
root
- App1
- App1a
- App1b
- etc
- App2
- etc
- Utils
Our build scripts, test utilities, apps used during the build, etc are stored in Utils. What I want to do is only perform a build when changes occur anywhere in root except for Utils. I've seen the option to exclude paths in SO but it's only with GIT libraries, is this possible with TFVC?
The solution I'm using to work around this is from Triggering Azure DevOps builds based on changes to sub folders
, but the build still executes, not the actual build mind you, but the pipeline which then triggers a notification to the team that it was successful. Ultimately I don't want it to run at all unless changes have been made outside of Utils. I also don't want to re-organize the folder structure either since a lot of our utilities have relative paths. I've got the trigger setup as
Thanks in advance.
You can exclude the utils folder in the CI trigger options: