Deploy Manual only after approval in Gitlab - gitlab

We have two stages , Build and deploy in our project.
Every time user creates a merge request from Feature branch to Master(PROD) ,it starts the pipeline with the build stage and stops for manual action to deploy.
Approval is only set for merge request and after the pipeline is successful it would merge to master.But the developer/approver can start the manual action to deploy without even merge request approval .
I want the user or approver to click the manual button only after the merge request is approved. Is it possible to control this or can i add a stage in-between only for approval?
deploy prod:
<<: *deploy
stage: deploy prod
environment: PROD
extends: .dockerprod
when: manual

Related

Manualvalidation task sending email based on conditions

I am following the documentation and added a manual validation task to my YAML pipeline which has 3 stages ( QA-DEV-PROD).
The Manual validation is added to the Prod stage of the pipeline.
task: ManualValidation#0
timeoutInMinutes: 1440
inputs:
notifyUsers: |
[group#name]
instructions: 'Please validate the deployment'
onTimeout: 'resume'
Is there a way, where I can add a condition so the user requesting the release should not approve it"?
I know, I can do that via :
WebUI in Release pipeline
Add approvals based on the environments
However, looking for the option to do this via YAML instead of UI checks.
Any insights on this?

Azure Devops pipelines to trigger on PR complete

What I have to do is, I have 1 branch as below in the azure DevOps respository
dev
Then I create a new branch as dev-C123456, so now I have two branches (dev and dev-C123456)
Then I do some changes to dev-C123456 and I create a Pull Request from dev-C123456 to dev. So once the changes are reviewed, the approver will Approve and Complete the pull request.
Right after he clicks Completes, I want a pipeline to run.
Here's my
And I have a auzre-piplines-on-pr.yml which will trigger the pipeline. For example, in dev branch, I have like this;
pr:
branches:
include:
- dev
...
But it never triggers a pipeline, what should I do?
Right after he clicks Completes, I want a pipeline to run.
So put a trigger for the target branch.
trigger:
branches:
include:
- dev
That will run whenever a commit is made to dev, including when the commit is a PR merge commit.

Azure DevOps: Pipeline for all branches but master

I have a website project with two pipelines
1.- PROD pipeline, which is triggered on every master branch push. This builds the site, deploys it and sends an email to the whole company informing about the new version. This works perfectly so far ✅
2.- DEV pipeline: should be triggered on a push to ANY branch that is not master. Builds the site, deploys the site to a DEV stage and sends an email to the author of the commit.
Following the docs, this trigger configuration should trigger the DEV pipeline on all branches but master.
trigger:
branches:
exclude:
- master
include:
- '*'
However, if I then try run the pipeline in any branch that is not master, I get the following error: Encountered error(s): Could not find valid pipeline YAML file for this branch/tag
How can I setup the pipeline, so that it gets triggered by all branches but the master branch?
Thanks in advance for your help!
D
You have to have the YAML file in every branch you want it to trigger for, you cannot just have it in the master branch and expect it to trigger on another branch.

Manual approvals for stages in Azure Devops pipelines (YAML)

I have a stage that uses 6 deployment jobs that can either deploy to dev, staging or production depending on specific conditions.
For deploying to production, I'd like to add manual approvals. I am aware that deployment jobs can specify environments on which you can add manual approvals, but I'd like to approve the entire stage and not each individual deployment job. This way, I can approve the stage once and all 6 deployment jobs can run at once, instead of having to approve 6 times.
Is this possible? The documentation says it should be, but it doesn't say how. Besides, in the YAML schema for stages, it doesn't look like you can specify environments inside stages.
Currently there is no such a built-in feature to approve entire stage in YAML. We can only Define approvals and checks for the environments. The documentation you mentioned is also indicated that this is commonly used to control deployments to production environments.
However, there's already a suggestion ticket to request the feature. You could vote and add your comments for the suggestion ticket to achieve that in future release.
Looks like the ManualValidation task could help you there. Using dependsOn will allow all other jobs to complete before final approval.
Example:
jobs:
- job: waitForValidation
dependsOn: 'previousJobName'
displayName: Wait for external validation
pool: server
timeoutInMinutes: 4320 # job times out in 3 days
steps:
- task: ManualValidation#0
timeoutInMinutes: 1440 # task times out in 1 day
inputs:
notifyUsers: |
test#test.com
example#example.com
instructions: 'Please validate the build configuration and resume'
onTimeout: 'reject'

how to get target branch from a pull request using azure devops api or other methods?

I'm trying to make a single build pipeline for 3 env (dev, qa, prod) but with ability to choose which one to build from.
The idea is to keep the pipeline on prod branch or another repo, and not having it in every env.
The issue now is that on a PR it will start the pipeline only on master(prod) branch as it shall contain the yml file.
Is there a way to get the PR target branch in order to add additional conditions for PR triggers?
how to get target branch from a pull request using azure devops api or other methods?
Agree with Yan Sklyarenko. Azure devops provides us with some predefined variables, like:
System.PullRequest.IsFork
System.PullRequest.PullRequestId
System.PullRequest.PullRequestNumber
System.PullRequest.SourceBranch
System.PullRequest.SourceRepositoryURI
System.PullRequest.TargetBranch
To get the target branch from a pull request, we could use the predefined variable System.PullRequest.TargetBranch.
So, we could use this predefined variable as condition:
condition: and(succeeded(), eq(variables['System.PullRequest.TargetBranch'], 'refs/heads/master'))
You can still have one build pipeline.
PR triggers are for github/bitbucket repositories. You can create branch policy which triggers your code etc.
The conditions you can have on each step/task:
conditions in Azure DevOps
for example:
- stage: B
condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))
with that condition this stage will run, only when source branch is named "master"

Resources