Azure-Devops pipeline not building automatically when yaml file pushed along with code - azure-devops

I'm trying to implement azure automatic pipeline build with azure-pipelines.yaml
i have tried the below methods in order to get it work.
azure-pipelines.yaml(yml)
.vsts-ci.yml(yaml)
.azure-pipelines.yaml(yml)
But when I'm trying with UI it's detecting.
Is it possible to build auto build pipeline in Azure-devops?

If you're building a GitHub repo in an Azure DevOps pipeline, there's some stuff you need to setup.
Azure Pipelines can automatically build and validate every pull request and commit to your GitHub repository. This article describes how to configure the integration between GitHub and Azure Pipelines.
If you're new to Azure Pipelines integration with GitHub, follow the steps in Create your first pipeline to get your first pipeline working with a GitHub repository, and then come back to this article to learn more about configuring and customizing the integration between GitHub and Azure Pipelines.
Source: Build GitHub repositories.
If you explicitly need a DevOps Pipeline to build your GitHub repo, have a look at the article linked to above. Otherwise think about either working with GitHub Actionshttps://github.com/features/actions on your GitHub repo, or hosting your repo in Azure Repos.

Depending on where your repository is located you should place your .yml file inside this repository in order to work with the trigger. You should also use the trigger keyword.
Then when you create your pipeline, you will choose Github, Azure Repos Git, whatever you use and select existing pipeline.
If you use the starter pipeline of Azure Devops, the pipeline will trigger out of the box when a commit is pushed on the main branch.
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
You can change main to which ever branch you need to trigger automatically.

Related

How do I download GitHub Artifacts from Azure DevOps Release Pipeline

I have a GitHub workflow that creates Artifact(s). I also have a last step within that workflow that triggers an Azure DevOps Release Pipeline. I modified an existing release pipeline to change the artifacts from an ADO Build Pipeline to GitHub (and made the service connection in ADO).
- uses: Azure/pipelines#v1
with:
azure-devops-project-url: 'https://dev.azure.com/some_org/some_project'
azure-pipeline-name: 'Name_Of_Release_Pipeline'
azure-devops-token: '${{ secrets.ADOPAT }}'
So the issue is that the Release Pipeline will not retrieve nor download the associated build artifact from GitHub. I can see that the GitHub workflow build information is stored in various Environment Variables, so the Release Pipeline is retrieving various metadata from the GitHub build, but why won't it download?
FYI - There is a ADO task that does download GitHub "release" artifacts but the GitHub repo I am building has not yet created a "release" and thus there are no artifacts to download. So that doesn't help.
You can try to install the Azure DevOps extension "GitHub Actions" to your Azure DevOps organization where the release pipeline is in.
This extension contains two build/release tasks:
Run a GitHub Workflow
Download GitHub Workflow Artifacts
For your case, you can try to use the Download GitHub Workflow Artifacts task in your release pipeline to download the artifacts from the latest run of the specified GitHub workflow.

how can a git repository be automatically updated when imported to azure?

I have a git repository that has been imported to azure repos but when I make a new commit it doesn't reflect the new commit on azure, is there some config I need to enable to allow this?
Sorry if the question seems dumb but I have been navigating through the UI and I can't see how to achieve this
thank you for all your help
There are many ways to achieve your needs. You can refer to the sample I implemented using Azure pipelines(I assume your repository is imported from GitHub to azure repos):
1.Create a pipeline and choose your GitHub repo as source:
2.Here is my configuration of the yaml file:
trigger:
- '*'//This pipeline will run whenever you push an update to the GitHub repo
pool:
vmImage: 'windows-latest'
steps:
- task: gitmirror#0//You can install this task in marketplace
inputs:
GitRepoUrl: 'https://{PAT}#dev.azure.com/{Organization Name}/{Project Name}/_git/{Repo Name}.git'//This is the URL of Azure Repo, you need to add a personal access token in the URL
3.Now, when you update the files in GitHub, it will trigger the pipeline in Azure DevOps and then update your Azure repository.

Merge GitHub branches from Azure

I am setting up CI/CD at work and there is one step I’m not sure how to do and furthermore, if it is a right thing do.
For background, I am used to develop in C# with Visual Studio, source code in TFS and deploying with basic script that copies files on the intranet.
Now, I’m requested to setup Build and Release pipelines on Dot Net Core projects in GitHub.
I have three branches on this project: DEV, RELEASE and MASTER
I created one pipeline that triggers on DEV’s commits, creates an artefact and deploy to DEV server.
Those are the pipelines that deploy all developers work to a DEV server where they run their own tests.
Next step, when we want to deploy to staging servers, we click a button in Azure, this merge the DEV branch to the RELEASE branch but I know close to nothing in GitHub, not even sure those are the appropriate words.
When the merge is done, this will trigger a build pipeline that will create a different artefact, when this artefact is updated, deploy to staging server.
Once this release is validated on Staging and Quality, we would merge RELEASE to MASTER and do the same until PROD servers. It is all on intranet and self-hosted agents.
Is that a good way of doing things? Can it be done this way? I need a PowerShell task or is there something that exists?
If you are using Azure DevOps pipeline, the pipeline should select GitHub for repository type, then we can configure the CI trigger.
a. Configure CI trigger:
Classic steps:
1.Open project setting->Service connections->select GitHub-> create a new GitHub service connection
2.Create a new build pipeline via classic editor-> Select GitHub as the source.
3.Open pipeline->select the tab Triggers-> enable the option Enable continuous integration and configure the Branch filters
b.YAML steps:
1.Open project setting->Service connections->select GitHub-> create a new GitHub service connection
2.Create a new build pipeline and select GitHub(YAML)
c.The sample of Check out GitHub repositories in your pipeline
resources:
repositories:
- repository: MyGitHubRepo # The name used to reference this repository in the checkout step
type: github
endpoint: MyGitHubServiceConnection
name: MyGitHubOrgOrUser/MyGitHubRepo
trigger:
- {branch name}
Configure CD trigger:
Please refer to this doc to configure the release trigger.
If you are using GitHub action.
Please select the correct workflow to configure the CI/CD, Please refer this doc for more details
CI sample:
on:
push:
branches:
- ' DEV'
Update1
When Dev branch is updated, it is built and deployed to Dev server by pipeline.
Create build A and release B, configure the CI build trigger, when the branch Dev is updated, it triggers the build pipeline A, and when build pipeline A is completed, it triggers the release pipeline B.
click a button to synchronize Dev branch to Release branch.
We cannot see the button, as a workaround, we can add task powershell and call the API to create pull request and complete the pull request. We also can add task cmd and publish the code via git cmd

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'

Azure DevOps pipeline trigger does not fire

Problem
Azure DevOps has a feature (documented here) to trigger a pipeline on completion from another pipeline.
This works fine in a test organization, but it won't work in our main organization.
There could be something on the organization, project, repository or even branching level, but I'm currently stuck and any help would be appreciated!
Pipelines
Pipeline Pipeline B should run automatically when pipeline Pipeline A completes.
File pipeline-a.yaml for Pipeline A:
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo Hello, world!
displayName: 'Do something'
File pipeline-b.yaml for Pipeline B:
trigger: none
pool:
vmImage: 'ubuntu-latest'
resources:
pipelines:
- pipeline: pipeline-a
source: 'Pipeline A'
branch: master
trigger:
branches:
- master
steps:
- script: echo Hello, world!
displayName: 'Do something'
Organizations
In my test organization the above pipelines run like a charm. This means that Pipeline A runs on a commit, and after completion, Pipeline B runs automatically.
Yet in our production organization, Pipeline B does not run automatically.
Discovery
Both pipelines run fine when started manually, in both organizations
All Preview features are equal on organization and personal level for both organizations, including the Multi-stage pipelines feature.
The production organization has branch policies on master, while the test organization does not have policies. I don't see a connection with pipeline triggers and did not investigate this.
Installing extensions to have them equal on test and production does not make a difference.
The test organization seems to be in the slow ring and was still on Sprint 161. EDIT: The issue persists after the organization was updated to Sprint 162.
It works when I use the classic editor and manually create a build completion trigger. But this overrides the YAML pipeline trigger and I don't want to do this (I want to generate the pipeline and it's triggers)
Deleting and re-adding the pipeline did the trick. So keep the YAML file but delete the pipeline and add it again.
The Azure DevOps backend seems to miss a relationship between pipelines now and then.
We troubleshot a similar problem today. With Pipeline-A defined as a resource that is meant to be consumed by Pipeline-B.
The consuming pipeline was never being triggered. Deleting and recreating the pipeline did not work for us. This work\pipeline was net new and on a feature branch. That ended up being important.
The ultimate fix was defining that feature branch as the Default branch for manual and scheduled builds in Pipeline-B. You can find that setting tucked away in Pipeline -> Edit -> triggers -> yaml-> Get Sources. Expect that as we promote this code to the main branch we will need to update the setting.
So it seems like the Default branch for manual and scheduled builds would be better named
Default branch for manual and scheduled builds and Pipeline Completion Triggers
In my case it was as simple as the source pipeline completing with an error. Testing with a very simple non erroring pipeline and the code worked fine.