gpt4 book ai didi

jenkins - 脚本管道中的条件何时?

转载 作者:行者123 更新时间:2023-12-04 15:41:03 28 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Jenkinsfile - Conditional stage execution in the Script Pipeline syntax

(5 个回答)


2年前关闭。




在声明式管道中,我们有以下条件:

pipeline {
agent any
stages {
stage('Example Build') {
when {
changeset 'service1\**'
}
steps {
echo 'Building'
}
}
}
}

有什么方法可以在脚本化管道中做一些事情吗?

最佳答案

您可以像这样以某种方式检查与特定模式匹配的文件(未测试)

创建一个函数来检查所需目录中的更改...

@NonCPS
boolean isMyDirChanged() {
for (changeLogSet in currentBuild.changeSets) {
for (entry in changeLogSet.getItems()) { // for each commit in the detected changes
for (file in entry.getAffectedFiles()) {
if (file.getPath() ==~ /^service1/) {
return true
}
}
}
}
return false
}

...然后使用该函数来确定是否应该执行某些代码
if (isMyDirChanged()) {
print ('Building')
}

关于jenkins - 脚本管道中的条件何时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57769173/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com