Manual Trigger on Azure Pipelines Stages (YAML)

北战南征 提交于 2020-06-08 07:36:47

问题


I'm setting up a pipeline using Azure Pipelines YAML format. I have created 3 stages: Build, Staging, and Production. As the names suggest, the Build stage builds the project and publishes the build artifacts. The Staging stage deploys to the Staging environment and the Production stage deploys to the Production environment.

In the Environments section of my project, I have added a check for the Production environment so that I can approve the deployment before going live.

The way that my pipeline works is that both Staging and Production stages are triggered automatically after the Build stage is finished. What I don't like about this is that when developers deploy their code to Staging, they need a couple of days to test it on Staging before pushing their code to Production. So, until then, my pipeline keeps running and waiting for my approval. The spinner at the top-left corner keeps spinning and the "Duration" field keeps passing.

Is there any ways that develpers manually trigger the Production stage whenever they are ready instead of the Build stage triggering it?


回答1:


Manual stages in yaml pipeline is not available currently. This feature request has been submitted to Microsoft. You can go and vote it up or submit a new one.

There are workarounds to achieve this.

You can move your staging and production stages to Classic Web UI Release Pipeline. Manually trigger a stage is available in Web UI Release pipeline. Please check here for more information.

Another way to achieve this is to separate your yaml pipeline into two yaml pipelines(stage pipeline and production pipeline). And disable CI build for production pipeline( in the pipeline edit page, click on the 3dots on the top right corner and choose triggers. Please refer to below pics).

So that you can manually run production pipeline after Developer done with their tests.




回答2:


I think there's a better way. You can add a pipeline variable which can can be overridden when starting the pipeline.

You have to add a new variable to your pipeline and chose 'Let users override this value when running this pipeline'.

In your pipeline add a condition to your stage such as:

condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['DEPLOY_PROD'], 'true')))

Now whenever you want a build to deploy to Production you start the build and then override the variable from here:

Set the value to 'true' and your build will trigger the stage you want.




回答3:


Yes it can be done. We do not do it in the yaml directly. But instead we add environment in YAML. And on environment we add manual trigger.

 environment: 'smarthotel-dev'

Environment and triggers are managed through UI.

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/environments?view=azure-devops




回答4:


you can set the trigger to none to disable CI and only trigger it manual

trigger: none


来源:https://stackoverflow.com/questions/58667596/manual-trigger-on-azure-pipelines-stages-yaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!