Scheduled trigger in Azure Pipeline multistage for a specific stage.

huangapple go评论62阅读模式
英文:

Scheduled trigger in Azure Pipeline multistage for a spesific stage

问题

我在Azure DevOps上有一个多阶段的流水线,我想每天晚上触发其中一个阶段,而其他阶段将由GitHub仓库中的更改触发。
我想知道是否可能仅针对一个阶段使用定时触发器,如果可以,如何操作?根据我在Google上找到的信息,似乎只能用于整个流水线。
如何在特定的日期和时间触发一个阶段?

以下是流水线的样子:

name: Pipeline

trigger:
  branches:
    include:
      - master
      - refs/tags/v*

variables:

resources:
  repositories:

stages:
 - stage: Build
   jobs:
   - job: Build
     steps:

     pool:
       vmImage: 'ubuntu-latest'

 - stage: Deploy_Dev
   variables:
 
   jobs:
   - steps:

###每夜触发

 - stage: Deploy_Test
   variables:

   jobs:
   - steps:
英文:

I have a multistage pipeline on Azure DevOps, and I would like to trigger one of the stages every night but the other stages would be triggered by changes in GitHub repo.
I'm wondering if it is possible to use scheduled trigger for only one Stage, if so how? as I found in google, it seems it is only for entire pipeline.
How is it possible to trigger only one Stage in a specific day and time?

Here is how the pipeline looks like:

name: Pipeline

trigger:
  branches:
    include:
      - master
      - refs/tags/v*

variables:

resources:
  repositories:

stages:
 - stage: Build
   jobs:
   - job: Build
     steps:

     pool:
       vmImage: 'ubuntu-latest'

 - stage: Deploy_Dev
   variables:
 
   jobs:
   - steps:

###Nightly triggered

 - stage: Deploy_Test
   variables:

   jobs:
   - steps:

答案1

得分: 1

抱歉,您的请求是将特定文本翻译成中文。以下是翻译的文本:

"我想知道是否可以仅为一个阶段使用定时触发器,如果可以,如何操作?根据我在Google上找到的信息,似乎只能应用于整个流水线。如何在特定的日期和时间仅触发一个阶段?"

"恐怕没有现成的方法来实现这一点。正如您所知,它只适用于整个流水线。"

"作为这个问题的变通方法,您可以为此流水线设置UI定义的定时触发器:"

然后,为“Deploy_Test”阶段的作业添加一个自定义条件:

- stage: Deploy_Test
  jobs:
  - job:
    condition: and(always(), eq(variables['Build.Reason'], 'Schedule'))
    steps:

在这种情况下,该阶段仅在由定时触发器触发的构建时执行。如果构建是由GitHub存储库中的更改触发的,阶段“Deploy_Test”将被跳过。

请注意:此变通方法的限制是,当您的流水线由定时触发器触发时,阶段“build”和“Deploy_Dev”也会执行。

希望对您有所帮助。

英文:

> I'm wondering if it is possible to use scheduled trigger for only one Stage, if so how? as I found in google, it seems it is only for entire pipeline. How is it possible to trigger only one Stage in a specific day and time?

I am afraid there is no such out of box way to achieve that. As you know, it is only for entire pipeline.

As workaround for this question, you could set UI defined scheduled triggers for this pipeline:

Scheduled trigger in Azure Pipeline multistage for a specific stage.

Then add a custom condition for the job of Deploy_Test stage:

 - stage: Deploy_Test
   jobs:      
   - job:
     condition: and(always(), eq(variables['Build.Reason'], 'Schedule'))
     steps:

In this case, the stage only executed when the build triggered by scheduled trigger. If the build is triggered by changes in GitHub repo, the stage Deploy_Test stage will be skipped:

Scheduled trigger in Azure Pipeline multistage for a specific stage.

Note: The limitation of this workaround is that when your pipeline is triggered by a scheduled trigger, the stage build and Deploy_Dev are also executed.

Hope this helps.

huangapple
  • 本文由 发表于 2020年1月6日 23:21:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定