如何在Jenkins中使用条件语句。堵塞

发布于 2025-02-10 03:25:26 字数 426 浏览 2 评论 0原文

我正在尝试根据变量设置詹金斯管道作业的超时。

我有这样的东西:

    pipeline {
        agent any
        options {
            timeout(time:6, unit:'HOURS')
    
        }
}

我希望只有在变量为真时才能设置此超时。类似的事情:

pipeline {
    agent any
    options {
        if (timerCause) {
            timeout(time:6, unit:'HOURS')
       }
    }
}

如果> 在选项块中的语句时,我无法使用进行此操作。任何指针都会很棒。谢谢 :)

I am trying to set a timeout on a Jenkins pipeline job based on a variable.

I have got something like this:

    pipeline {
        agent any
        options {
            timeout(time:6, unit:'HOURS')
    
        }
}

I will like this timeout to be set only when a variable is true. Something like this:

pipeline {
    agent any
    options {
        if (timerCause) {
            timeout(time:6, unit:'HOURS')
       }
    }
}

I can't do this with if or when statements in the options block. Any pointers would be great. Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘴硬脾气大 2025-02-17 03:25:27

如果未设置标志,您如何设置默认值。

def flag = false
def to = Integer.MAX_VALUE
if(flag) {
    to = 500
}

pipeline {
    agent any
    options {
         timeout(time:to, unit:'SECONDS')
    }

How about you set a default value if the flag is not set.

def flag = false
def to = Integer.MAX_VALUE
if(flag) {
    to = 500
}

pipeline {
    agent any
    options {
         timeout(time:to, unit:'SECONDS')
    }
猥琐帝 2025-02-17 03:25:27

不知道timercause是什么,也不愿意猜测,我只推荐三元运营商:

pipeline {
    agent any
    options {
        timeout(time: timerCause ? 6 : 9999, unit:'HOURS')
    }
}

Not knowing what a timerCause is, and not willing to guess, I'd just recommend the ternary operator:

pipeline {
    agent any
    options {
        timeout(time: timerCause ? 6 : 9999, unit:'HOURS')
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文