我有一个包含构建阶段 - 测试 - 性能测试 - 部署的管道。
我只想在周三晚上在管道中运行性能测试阶段,因为运行和发布报告需要大量时间。
这种情况是否可以合并到 jenkinsfile 中?请指教。
提前致谢。
答案 0 :(得分: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。
将模式设为 :yyyy-MM-dd HH:mm:ss z EEE