Jenkinsfile-如何使cron触发器仅在特定阶段启动? [英] Jenkinsfile - How to make a cron trigger kick off only a specifc stage?

查看:137
本文介绍了Jenkinsfile-如何使cron触发器仅在特定阶段启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下触发器的Jenkinsfile:

I have a Jenkinsfile with the following triggers:

  triggers {
  cron('0 * * * 1-5')
}

因此它将在星期一至星期五的每小时的顶部触发.

So it will trigger at the top of the hour, every hour, Monday through Friday.

在Jenkinsfile中,我有多个阶段,例如:

In the Jenkinsfile I have a number of stages like:

stage('CI Build and push snapshot') {
    when {
      anyOf { branch 'PR-*';branch 'develop' }
    }
 .
 .
 .
  stage('Build Release') {
    when {
      branch 'master'
    }
 .
 .
 .
  stage('Integration Tests') {
    when {
       ? // not sure what goes here
     }

我想做的是,当该触发器启动时,我只希望运行Integration Tests阶段.我该如何实现?我认为现在拥有的每个阶段都将运行.

What I want to do is, when that trigger is kicked off, I only want the Integration Tests stage to run. How do I achieve this? I think with what I have now every stage is going to be run.

谢谢!

推荐答案

我能够使用以下方法使其工作:

I was able to get it working using something like:

 stage('CI Build and push snapshot') {
    when {
      anyOf { branch 'PR-*';branch 'develop' }
      not {
        expression { return currentBuild.rawBuild.getCause(hudson.triggers.TimerTrigger$TimerTriggerCause) }
      }
    }

 stage('Integration Tests') {
    when {
       branch 'develop'
       expression { return currentBuild.rawBuild.getCause(hudson.triggers.TimerTrigger$TimerTriggerCause) }
     }

这篇关于Jenkinsfile-如何使cron触发器仅在特定阶段启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆