在 jenkins 管道中触发特定构建
Trigger a specific build in jenkins pipeline
我有一个包含构建 - 测试 - 性能测试 - 部署阶段的管道。
我只想在星期三晚上 运行 进行性能测试阶段,因为 运行 和发布报告需要很多时间。
这个场景可以合并到 jenkinsfile 中吗?请指教
提前致谢。
是的,请参阅下面的代码/方法,这将使您了解如何在特定日期或特定时间执行特定阶段condition.You可以根据您的要求更改条件。
# 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
)
}
}
}
}
配置构建时间戳:如果您的构建时间戳未配置为获取日期信息,那么您可以使用以下方法
https://plugins.jenkins.io/build-timestamp/
管理 Jenkins -> 配置系统 -> 构建时间戳 -> 点击启用 BUILD_TIMESTAMP。
将模式设为 :yyyy-MM-dd HH:mm:ss z EEE
我有一个包含构建 - 测试 - 性能测试 - 部署阶段的管道。
我只想在星期三晚上 运行 进行性能测试阶段,因为 运行 和发布报告需要很多时间。
这个场景可以合并到 jenkinsfile 中吗?请指教
提前致谢。
是的,请参阅下面的代码/方法,这将使您了解如何在特定日期或特定时间执行特定阶段condition.You可以根据您的要求更改条件。
# 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
)
}
}
}
}
配置构建时间戳:如果您的构建时间戳未配置为获取日期信息,那么您可以使用以下方法
https://plugins.jenkins.io/build-timestamp/
管理 Jenkins -> 配置系统 -> 构建时间戳 -> 点击启用 BUILD_TIMESTAMP。
将模式设为 :yyyy-MM-dd HH:mm:ss z EEE