I would like to create a manual job run on demand with GUI that will make mr from master to current branach and re-trigger the trigger.
I have such a track but after triggering it I don't want to trigger the triggers again.
.trigger:
stage: trigger
inherit:
variables: false
trigger:mock:
extends: .trigger
trigger:
project:mock
branch: ${CI_COMMIT_BRANCH}
refresh-environment:
stage: refresh-environment
when: manual
trigger:
include: .refresh-environment-ci.yml
variables:
GITLAB_TOKEN: ${GITLAB_TOKEN_INT_1}
Any hint?
Related
I have a CD pipeline, which uses a CI pipeline as a resource. In my CD pipeline, I have triggers that exclude some project paths that I have in the solution, in my resource I have included my main branch on the trigger.
CD pipeline:
trigger:
branches:
include:
- main
paths:
exclude:
- src/Customer.Worker.Converter
pool:
vmImage: "ubuntu-latest"
resources:
pipelines:
- pipeline: customer-ci
source: Customer-API-CI
trigger:
branches:
include:
- main
stages:
...
What I want to happen is when I push from my main branch, the CI pipeline runs and activates the CD pipeline only when what I changed is not in the paths I excluded from the trigger, in this case, when I change something in the Customer.Worker.Converter project, I don't want this pipeline to be triggered.
But even when I change something from path Customer.Worker.Converter, the CD pipeline triggers after the CI pipeline, ignoring my exclude path trigger and apparently obeying the CI resource pipeline trigger I use.
Is there any way to get what I want using pipeline resource?
As per this article, you've defined two separate triggers, but I think you only want one when the CI pipeline completes. At the moment, you will trigger changes based on the CI pipeline and when there are code-pushes.
If you only want the CD pipeline to be triggered when the CI pipeline completes, change the trigger for the CD pipeline to be none:
# ci pipeline
trigger:
branches:
include:
- main
paths:
include:
- src/Customer.Worker.Converter/*
----
# cd pipeline
resources:
pipelines:
- pipeline: customer-ci
source: customer-api-ci
trigger:
branches:
include:
- main # only trigger the CD pipeline when the CI pipeline on 'main' completes.
# do not trigger changes to this pipeline when code-changes are made
trigger: none
In theory, you can combine resource triggers:
When filters are specified, the source pipeline run must match all of the filters to trigger a run.
So one possibility would be to configure the cd pipeline to only run when the CI pipeline completes on the main branch and has a specific tag.
I have 2 pipelines. i need B pipeline to run after A pipeline completes and I also need B pipeline to triggers by Every test branch changes. I am not sure if using resources and trigger at the same file (B pipeline) is correct?
trigger:
batch: true
branches:
include:
- test
resources:
pipelines:
- pipeline: A
source: A
trigger: true
Test the scenario, it works as expected.
If that doesn't work, then please try to add the pipeline yaml file to Test branch, then create the pipeline B from Existing Azure Pipelines YAML file.
trigger:
batch: true
branches:
include:
- Test
resources:
pipelines:
- pipeline: A # Any Alias
source: A # The real pipeline name
project: Basic # Project name if from another project within the same org
trigger:
branches:
include:
- refs/heads/master
Is it possible to have a single file azure-pipelines.yaml that can :
Trigger a job A on a push from any branch BUT main
Trigger a job B on PR to main and all subsequent commit on that PR
Trigger a job C when main is merged
I have tried to play arround with trigger, pr keywords and even with condition(), variables['Build.Reason'], or System.PullRequest.TargetBranch but I didn't manage to reach the expected result.
I start thinking it cannot be done with a single file - am I wrong?
You can set conditions on your stages to run depending on a variable but I am not pretty sure this will work with your conditions. Maybe you could also combine some variable values.
For example source branch main and pr is created.
and(eq(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
Azure documentation sample:
variables:
isMain: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')]
stages:
- stage: A
jobs:
- job: A1
steps:
- script: echo Hello Stage A!
- stage: B
condition: and(succeeded(), eq(variables.isMain, 'true'))
jobs:
- job: B1
steps:
- script: echo Hello Stage B!
- script: echo $(isMain)
Keep in mind that triggers are appending resources. This means that if you specify a trigger like the below, it will be triggered whether the branch filter is triggered OR the pr is created.
trigger:
branches:
include:
- '*'
pr:
branches:
include:
- current
As you said this can be accomplished for sure with separate files for the pipelines.
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml
Your first question is possible by using trigger with include and exclude branches as below
trigger:
branches:
include:
- stage
- releases/*
exclude:
- master
Refer CI triggers in Azure Repos Git documentation to have more understanding.
When a pipeline is triggered by a repository resource trigger I need to be able to determine metadata about the triggering repository (such as repo name and branch).
It sounds like these variables should be set during a pipeline run that was triggered by a repository resource; however, their values are blank when I do echo $(resources.triggeringAlias) or env | sort in a pipeline run that was triggered by a repository resource.
UPDATE: the predefined variables for Build.Repository.Name and Build.SourceBranchName now work as expected when used with a repository trigger. So, while I'm no longer in need of resources.triggeringAlias and resources.triggeringCategory, they still aren't working.
I need to be able to determine metadata about the triggering
repository (such as repo name and branch)
We can use $(Build.Repository.Name) and $(Build.Repository.Uri) to get repo name and repo uri.
And $(Build.SourceVersion) can be used to get CommitId, $(Build.SourceBranch) or $(Build.SourceBranchName) can be used to get branch info.
Just note we must also checkout the triggering repo to make above variables work to fetch the info of triggering repo, otherwise those variables will always represents the value of triggered repo:
steps:
- checkout: self
- checkout: TheTriggeringRepo
Some details:
I have a triggering repo PipelineA, and the triggered repo PipelineB. PipelineB's azure-pipelines.yml file:
resources:
repositories:
- repository: PipelineA
type: git
name: PipelineA
trigger:
- master
steps:
- checkout: self
- checkout: PipelineA
- task: Bash#3
inputs:
targetType: 'inline'
script: |
echo $(Build.Repository.Name)
echo $(Build.SourceBranch)
So this pipeline will be triggered by both PipelineA repo and PipelineB repo.
When PipelineB repo has changes:
When PipelineA repo has changes:
It's clear the $(Build.Repository.Name) variable can work well to output the real trigger repo if we checkout both these two repos. So just make sure you checkout those triggering repos, then my variables above would work for you.
resources:
pipelines:
- pipeline: client-qa-deployment ## Resources.TriggeringAlias will be 'client-qa-deployment' if this resource gets triggered.
source: benjose.dev-code
trigger:
stages:
- client_deploy_qa
- stage: qa_smoketest
displayName: Smoke Test on QA Environment
condition: eq(variables['Resources.TriggeringAlias'], 'client-qa-deployment')
pool:
vmImage: 'windows-latest'
jobs:
- job: TestQA
steps:
- script: echo Hello, $(Resources.TriggeringAlias)!
displayName: 'Running Smoke Test on QA Environment'
Hello, client-staging-deployment!
I believe the above snippet will help you to understand the syntax and usage of Resources.TriggeringAlias. This variable will be helpful if we have multiple resources in the same pipeline and to find out which resource got trigged.
My pipeline trigger in Azure DevOps does not fire.
Enviroment:
PipelineA (branch dev)
PipelineB (branch dev)
PipelineB should be fired if PipelineB was running successfully
Here is my current code of PipelineB.yaml
trigger: none
resources:
pipelines:
- pipeline: build_pipeline
source: PipelineA
branch: dev
trigger:
branches:
- dev
steps:
- task: Bash#3
inputs:
targetType: 'inline'
script: |
echo 'Hello world'
It worked in the past, but suddenly it stopped
Here's the document of Pipeline Triggers, please check this statement:
However, if the two pipelines use different repositories, then the triggered pipeline will use the latest version of the code from its default branch.
Cause of your issue:
The triggered pipeline is PipelineB in your scenario, and the default branch is always the master. Since the pipeline trigger for dev branch of PipelineA is defined in your dev branch instead of the default master branch, it's expected behavior that the pipeline trigger won't fire.
To make the pipeline trigger work:
1.You can choose to define the pipeline trigger for dev of PipelineA in default master of PipelineB.
2.Or you can change the Default branch for manual and scheduled builds of PipelineB (Change it from master to dev). You can find detailed steps about how to find this setting from #2 of this answer.
Both two choices above can resolve your issue and make the pipeline trigger work.
I just created almost identical pipeline
trigger: none
resources:
pipelines:
- pipeline: build_pipeline
source: kmadof.devops-manual (14)
branch: master
trigger:
branches:
- master
steps:
- task: Bash#3
inputs:
targetType: 'inline'
script: |
echo 'Hello world'
and all works fine. Are you sure you run PipelineA on dev branch?