Get triggered build resource from Azure DevOps build - azure-devops

I am using 'batched CI' trigger for a number of pipelines in our Azure DevOps Server installation, as in
trigger:
batch: true
branches:
include:
- master
These pipelines in turn use build artifacts from another pipeline for performing their actions:
resources:
pipelines:
- pipeline: artifacts
source: Artifacts
trigger:
branches:
include:
- master
After a triggered build has finished, I need to retrieve information on the exact build resource the triggered build was using, i.e. what artifacts it was based on. But I cannot find any information on that.
I've tried the REST API for build items, and that is supposed to contain properties TriggerInfo and TriggeredByBuild. But these never contain any information.
The information is clearly possible to retrieve, since every build summary in Azure DevOps contains the Related/Consumed artifact information. But does anyone here know how to retrieve this information?

Related

In Azure DevOps, create a build + release pipeline that ONLY pulls and releases web.configs

In Azure DevOps, how would i create a build + release pipeline that ONLY pulls and releases web.configs.
I mean pull multiple web.configs from TFS and then update just those files in the release
In Azure DevOps you can specify what files you would like to have the pipeline use in the trigger. Once you have this set up the build pipeline will only pull the web config and then you can manipulate them however you would like.
Here is the Microsoft documentation on pipeline triggers.
trigger:
branches:
include:
- master
paths:
include:
- web.config

Azure DevOps - Pipeline triggering pipeline

Like many before me I'm struggling hard with configuring pipeline triggers in Azure DevOps.
Background:
single project in the Organization
three branches: main, Infrastructure, Application
The branches are kind of independent of each other. They are never merged into main either.
I have a pipeline which deploys two App Services. The YAML file for this pipeline is in the Infrastructure branch. The Default branch for manual and scheduled builds is set to Infrastructure.
Then I have 2 pipelines, each to deploy a different App to the App Service. The YAMLs for those pipelines are in the Application branch. The Default branch for manual and scheduled builds is set to Application.
By themselves, the pipelines work perfectly fine. However what I am trying to achieve is to trigger the App pipelines after the App Service pipeline finishes. And no matter what combination of settings I try, I can't get it to work.
This is currently how it looks like in the n-th version of the YAML:
name: 'deploy-webapp-002'
pool:
vmImage: windows-latest
resources:
pipelines:
- pipeline: 'Deploy App Services' # Internal name of the source pipeline, used elsewhere within this YAML
# e.g. to reference published artifacts
source: deploy-appservices # Azure Pipelines name of the source pipeline referenced
project: HomeLab # Required only if the source pipeline is in another project
trigger:
branches:
include:
- Infrastructure
- Application
pr: none
trigger: none
Is it even possible to do what I'm trying to do?
If yes, what settings should be specified in the Resources/Pipelines section in the YAML, and how should the Default branch for manual and scheduled builds look like for each of those pipelines?
I can reproduce the same issue when I put the YAML files separately in two branches and set the default branch.
Refer to this doc: Define a pipelines resource
When you define a resource trigger, if its pipeline resource is from the same repository (say self) as the current pipeline, triggering follows the same branch and commit on which the event is raised. But, if the pipeline resource is from a different repository, the current pipeline triggers on the default branch of the self repository.
In your case, you are using the same repo. So triggering follows the same branch and commit on which the event is raised.
To solve this issue, you need to copy the YAML file in Application Branch to Infrastructure Branch.
On the other hand, you can also try to set Build completion trigger manually on UI.
For example:

Azure DevOps run Pipeline when GitHub is pushed but ignore some certain files

I have a Pipeline on Azure DevOps that runs automatically - the trigger is a push to the master branch of my GitHub repo.
This pipeline will build a Docker image and push it to container registry, restart the app, etc. to update the app with the latest changes.
However, there are some certain files I want this Pipeline to ignore (for example, README.md). Is there any way that I can achieve this?
You can a path filter for your pipeline trigger.
If you are using yaml pipeline. You can set the path filter as below:
trigger:
batch: true
branches:
include:
- master
paths:
exclude:
- README.md
If you are using classic UI pipeline. You can go to the Triggers tab and set the path filter

Azure Devops YAML Pipeline Trigger on different repositories

Is it possible to have a yaml pipeline trigger on commits/PRs for branches of different repositories (e.g. Repo A) to the one the azure-pipelines.yaml file is in (e.g. Repo B)?
I'm aware I can build the pipeline against Repo B and have it checkout Repo A using e.g:
resources:
repositories:
- repository: Repo A
type: github
endpoint: ***
name: ***/RepoA
trigger:
- master
But the trigger is only applying to Repo B, i.e. when I make a commit on master to Repo A, the pipeline does not trigger.
The "Sprint 173" release seems to be including the multi-repo triggers feature. I suspect you might be missing the ref.
Here is an example that shows how to define multiple repository
resources in a pipeline and how to configure triggers on all of them.
trigger:
- main
resources:
repositories:
- repository: tools
type: git
name: MyProject/tools
ref: main
trigger:
branches:
include:
- main
- release
The pipeline in this example will be triggered if there are any
updates to:
main branch in the self repo containing the YAML file
main or release branches in tools repo
Unfortunately Multi-repo triggers is supported for Github repo resources yet.
As it is said in the document:
Repository resource triggers only work for Azure Repos Git repositories at present. They do not work for GitHub or Bitbucket repository resources.
If you were using Azure Repos Git repositories. You need to specify the trigger section for the repository resources in order to enable the Multi-repo triggers. See document here for more information.
Since you are using github, you can use pipeline completion triggers as workaround. You can refer to below steps to setup a pipeline completion trigger for RepoB pipeline.
1, Set up the triggering pipeline for RepoA.
You can create a pipeline for github RepoA in azure devops. Classic UI pipeline is recommanded, for it won't add a azure-pipelines.yaml file in your RepoA.
I suggest you add a empty agent job(without any tasks)in the triggering pipeline. So that the pipeline run will always be successful.
You need to Enable continuous integration for this triggering pipeline. So that the commits/PRs for branches in RepoA will automatically trigger this pipeline.
In the pipeline Edit page, Go to Triggers tab, Check Enable continuous integration, Add the branches you want to enable CI in the Branches Filters section
2, Set up pipeline resources in triggered pipeline (ie. azure-pipelines.yaml file for RepoB)
Add the pipeline resources and specify the trigger section in the pipeline resource. See below example:
resources:
repositories:
- repository: Repo A
type: github
endpoint: ***
name: ***/RepoA
pipelines:
- pipeline: repoAPipeline # Name of the pipeline resource
source: triggeringPipeline-RepoA # Name of the triggering pipeline
trigger:
branches:
- releases/*
- master
When changes are made to RepoA, the triggering pipeline will be triggered and complete successfully. When the triggering pipeline is completed, Pipeline for RepoB will be triggered.
By setting up the triggering pipeline for RepoA and the pipeline resources in pipeline of RepoB. You can achieve the same effect with Multi-repo triggers.

Azure Devops CI pipeline trigger for multi projects

I have a following structure:
Test-A and Test-B projects created on Azure Devops. Test-A project's CI build pipeline will produce an artifact.
Test-B's pipeline uses the artifact produced by Test-A's CI pipeline in its build. I am able to download the build artifact of Test-A project and use it.
The problem I am facing here is I am unable to do a CI automatic trigger with project Test-A dependency in project Test-B i.e when ever I make changes and push the changes on to Test-A github repo or whenever I do a new build on Test-A I want the build for Test-B to start automatically.
I have read the documentation on Azure devops but they are not working.
Link for pipeline trigger
Link for pipeline multi-trigger
Below is my .yml file.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
resources:
pipelines:
- pipeline: JustAName
project: Test-A
source: Test-A_CI
branch: master
trigger:
branches:
include:
- master
repositories:
- repository: justAnotherName
type: github
name: myGitRepo
endpoint: myGitServiceConnection
trigger:
branches:
include:
- master
steps:
- task: DownloadPipelineArtifact#2
inputs:
buildType: 'specific'
project: 'hashValue or Test-A'
definition: '1'
specificBuildWithTriggering: true
buildVersionToDownload: 'latest'
targetPath: '$(Agent.BuildDirectory)'
I am not sure where I am doing wrong or if it is a permission issue. I checked the logs to find any reference with the resources part in the yml but I had no luck.
Can someone suggest what is the best way to check what is the problem and resolve the issue.
Build completion option is disable in classic editor
The build completion option in the pipeline classic editor is limited to the pipelines within the same project. So it won't work for your scenario(the triggering pipeline and triggered pipeline reside in different project) even if it is enabled.
For issue build completion option is disabled. You can report this issue here. Click report a problem and select Azure Devops.
Resources pipeline trigger doesnot work properly sometimes. This similar issue has submitted to Microsoft by some other users. You can follow and vote on these cases or create a new one. Build Completion Triggers not working, Pipeline trigger not working as expressed in documentation
You can follow the workaround which using task TriggerPipeline given by #Hugh. You can also add a powershell task to call the rest api to queue another build pipeline. You can check this thread for example scripts
For your issue , there is a custom task in the Azure DevOps marketplace: Trigger Azure DevOps pipeline.
With this task you can trigger a build or release pipeline from another pipeline within the same project or organization but also in another project or organization.
To get started a PAT is needed with the appropriate rights to execute pipelines. Give the PAT the following rights depending on your scenario:
Triggering a Build: Build – Read & execute
When you have installed the extension, you can add this task into yaml. In the task setting ,you need to connect to a Azure DevOps Service connection. For detailed configuration, please refer to this.
steps:
- task: TriggerPipeline#1
inputs:
serviceConnection: 'triggerpipeline'
project: 'Test-B'
Pipeline: 'Build'
buildDefinition: 'xxx'
Branch: 'master'