【问题标题】:Trigger a specific build in jenkins pipeline触发詹金斯管道中的特定构建
【发布时间】:2021-06-04 19:18:45
【问题描述】:

我有一个管道,其中包含构建 - 测试 - 性能测试 - 部署阶段。

我只想在周三晚上在管道中运行性能测试阶段,因为运行和发布报告需要大量时间。

这种情况可以合并到 jenkinsfile 中吗?请指教。

提前致谢。

【问题讨论】:

    标签: jenkins


    【解决方案1】:

    是的,请参阅下面的代码/方法,它将让您了解如何在特定日期或特定条件下执行特定阶段。您可以根据需要更改条件。

    # Get the day from the build timestamp
    def getday = env.BUILD_TIMESTAMP
    getday = getday .split(" ")
    // Extract current day
    getday = getday [3]
    pipeline 
    {
      agent any
    
    stages {
     stage('Build') {
            steps {
                script {
                      // do something
                    )
                }
            }
        }
    stage('Performance test') {
          when 
                {
                    // Note: You can change condition as per your need
                    // Stage will run only when the day is Wed
                    expression {
                         getday == "Wed"
                    }
                }
            steps {
                script {
                      // do something
                    )
                }
            }
        }
    }
    
    

    配置 BuildTimestamp:如果您的构建时间戳未配置为获取日期信息,那么您可以使用以下方法进行操作
    https://plugins.jenkins.io/build-timestamp/
    管理 Jenkins -> 配置系统 -> 构建时间戳 -> 单击启用 BUILD_TIMESTAMP。 将 Pattern 设置为 :yyyy-MM-dd HH:mm:ss z EEE

    【讨论】:

    • 感谢分享代码和方法。还有一个问题,我想使用 Cron 触发特定阶段。我应该如何相应地修改代码?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 2018-11-28
    相关资源
    最近更新 更多