how to add manual intervention in build pipeline - azure

i have a build pipeline i want to add mannual intervention in the pipeline and when that manual intervention is done the user can click on resume the pipeline but i want to do this in build pipeline.
i checked in this https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/manual-validation?view=azure-devops&tabs=yaml but it looks like we need to do using stage pipeline in release pipeline. but i want this to happen in build pipeline

We seem have not such task for build pipeline, especially classic build pipeline.
If you want to add manual intervention in a build pipeline, you can try to set up this pipeline with YAML and add this run the Manual Validation task in an agentless job.
However, it might not be possible if you want to pause a running agent job in the build pipeline. Maybe you can try run the pipeline on a self-hosted agent with interactive mode.
[UPDATE]
You should use the Manual Validation task in an agentless job in the YAML pipeline, not in the classic build pipeline.
To set up an agentless job in the YAML pipeline, you need to set the value of 'pool' key to ne 'server'.
jobs:
- job: agentless-job
pool: server
To view more details, you can see "Server jobs".

To add a manual validation task in pipeline without creating a agent-less job you will need to define pool: server on the top of your steps. as below.
I got this from by referring to canary deployments but have tested the same works for rolling deployment and probably other steps introduced in the pipeline.
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops
pool: server
steps:
- task: ManualValidation#0
timeoutInMinutes: 1440 # task times out in 1 day
inputs:
notifyUsers: |
youremailadress#hotmail.com
instructions: 'Please validate the build configuration and resume'
onTimeout: 'reject'

Related

Gitlab pipeline - run the script with a rule

I want to send a slack notification as soon as trigger the pipeline build manually.
Steps I am following:
Go to your project’s CI/CD > Pipelines and select Run pipeline.
Choose the branch you want to run the pipeline for.
Input the variable and its value in the UI.
Click on the Run pipeline button
From the documentation I see:
How the pipeline was triggered. Can be push, web, schedule, api, external, chat, webide, merge_request_event, external_pull_request_event, parent_pipeline, trigger, or pipeline. For a description of each value, see Common if clauses for rules, which uses this variable to control when jobs run.
In this init stage I want to execute a script only when I run the pipeline using the above steps
init:
stage: init
environment: $DEPLOY_ENVIRONMENT
script:
- bundle exec fastlane slack_build_start_summary
rules:
- if: $CI_PIPELINE_SOURCE == "trigger" // also tried with "pipeline"
when: always
But I can't see this stage in the Gitlab pipeline stages.
I want to know which CI_PIPELINE_SOURCE ("trigger" or "pipeline" or something else?) I need to check when I trigger the pipeline manually from Gitlab using the above steps.
I got the answer here from the documentation
web -> For pipelines created by using Run pipeline button in the GitLab UI, from the project’s CI/CD > Pipelines section.
So I need to use:
- if: $CI_PIPELINE_SOURCE == "web"

Trigger Gitlab CI pipeline only when subproject pipelines are finished

I have 1 question regarding Gitlab pipeline triggering. We have multiple gitlab projects which trigger 1 common project. They are doing It separately. The idea is to trigger this project only when subprojects are finished. Is there are any way to do It better than create script which checks pipeline status via API? Because didn't find any out-of-the box solution for this
You can use the trigger:strategy. As per the docs:
Use trigger:strategy to force the trigger job to wait for the downstream pipeline to complete before it is marked as success.
So say you have build and test stages, and you want the trigger job in the build stage to succeed before moving on to the test stage, you could do something like this: =
downstream-build:
stage: build
trigger:
include: path/to/child-pipeline.yml
strategy: depend

Is there a way to translate a yaml build pipeline to a release pipeline using Azure Devops?

In my build pipeline I am running Pester tests and reporting to the output folder. During release I want to run these and only go to the next stage (deploy) if all tests pass. I am not concerned about the results, I just want to make sure that they all pass. I have tried to 'copy' my existing yaml file using the GUI however not sure of the best way to do this and variable scope. Is it possible to translate a build pipeline directly to an Azure release pipeline in Azure Devops and if so, what is the best approach for doing this?
I tried to translate it to json however i had an undefined error when I tried to import the json pipeline. I should also add that I can't see a solution by looking at the preview features for this.
I am afraid it is not possible to translate a build pipeline directly to an Azure release pipeline.
You need to manually add the same tasks which are in the build pipeline to the release stage. I believe it is not a complex work to create a stage with the same tasks in the release pipeline. You just need to add each tasks with the same configurations(copy and paste mostly). And create the same variables in Variables tab. Check document about classic CD release pipeline.
There is another workaround using multiple stages yaml pipeline instead of classic release pipepline.
With multiple stage yaml pipeline. You can just easily move your build yaml content in a stage. Check here for more information. See below:
trigger: none
stages:
- stage: Test
jobs:
- job: Pester tests
pool:
vmImage: windows-latest
steps:
..
- stage: Deploy
jobs:
- job: DeployJob
pool:
vmImage: windows-latest
steps:
..

How to use a single agent for multiple jobs/stages in azure devops YAML pipeline

I am working on Azure DevOps YAML pipeline, I am not sure whether we can use single agents through out the pipeline.
I have multiple jobs/stages - Build, Deploy, Post-Deploy, and want to assing that to a single agent, because it is consuming same artifacts.
Is there a way to assign a single agents through the pipeline.
Thanks in advance.
I dont want the agent to do checkout operation everytime for new job
Using the checkout keyword to configure or suppress this behavior.
steps:
- checkout: none
You can refer to this official document for details.
Yes, you can define a specific agent on YAML.
E.g:
pool:
name: AgentPoolName
demands:
- agent.name -equals AgentName
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/demands?view=azure-devops&tabs=yaml
If you cannot use a specif agent as #Savio Moreira suggested the only option that I found is to duplicate some steps.
In my case have a similar pipeline with 2 stage:
Build (To validate PR)
Visual Studio build
Visual Studio Test
VS test
Publish (To publish the Artifact after merge into master)
Visual Studio build
Copy file
Publish build artifacts
The Build part is trigger only when a PR is created using a condition in the YAML Stage and Enable Branch policies.
The Publish part is trigger only when there is merge into master.
It's a bit annoying that some steps need to be duplicated but the execution is unique, and with the same pipeline I can execute validation before merge and then create the artifact once the code is into master.
The checkout option doesn't help since in my case each stage is executed on a completely different container.
Yes there is a way all you need to do is to store the agent name of yo first job in a variable and then for any other job you need to ask for same agent. Its done like this -
jobs:
- job: A
steps:
- bash: |
echo "##vso[task.setvariable variable=AgentName;isoutput=true]$(Agent.Name)"
name: passOutput
- job: B
dependsOn: A
variables:
AgentName: $[ dependencies.A.outputs['passOutput.AgentName'] ]
pool:
name: pool1
demands: Agent.Name -equals $(AgentName)
steps:
- bash: |
echo $(AgentName)

Gitlab-CI : triggering a stage based on the Status of the previous stage

enter image description here
Hello - I'm using Gitlab 10.x Enterprise version.
This is in the context of a Production deployment to an environment having eight servers. The requirement is to deploy to one server first, and then after couple of days do a deployment to the remaining servers with the press of just one button.
Pipeline Stages:
Release-Tag-Creation -> Production-OneServer-Deployment -> OneButtonPush -> DeploytoAllServers
Question:
How can I tie the dependency between the stages "OneButtonPush" and "DeploytoAllServers"?. "DeploytoAllServers" stage should be kicked-off only when the Status of the job in the "OneButtonPush" stage is successful. "DeploytoAllServers" stage will have parallel jobs to deploy to each server.
I made few attempts based on the Gitlab CI documentation, but wasn't successful. Also, can the concept of Rolling deployment used in the context of GitLab-CI.
Thanks!
In Gitlab CI, the stages are run one after another. Each stage can have multiple jobs which run in parallel.
As per your use case, you'll need to have different stages each for Release-Tag-Creation, Production-OneServer-Deployment, OneButtonPush and DeploytoAllServers. You can have manual triggers for particular jobs (OneButtonPush in your case) by specifying when: manual in the job definition.
By default, if there is a job awaiting manual trigger, jobs from further stages will start executing considering the job with manual trigger as successful. To change this behavior one will need to use allow_failure: false. Mode details on allow_failure over here
If you want to run the Stage only after then specific one get successful you can use the needs
Example
image: maven:latest
stages:
- deploy_dev_lambda
- test_dev_lambda
deploy_dev_lambda:
stage: deploy_dev_lambda
image: maven:latest
script:
- ./deployLambda
environment: dev
variables:
TARGET_ENV: "dev"
TAG_NAME: main-$CI_COMMIT_SHORT_SHA
test_dev_lambda:
stage: test_dev_lambda
needs:
- deploy_dev_lambda
script:
- ./testLambda
So test_dev_lambda only run after the deploy_dev_lambda stage and if stage deploy_dev_lambda fails test_dev_lambda wont get executed.

Resources