在使用 Jenkins多分支管道作业时,如果在作业中选择Suppress Automatic SCM trigger
,则在索引分支后将停止构建该作业(强大的功能)。
但是由于某种原因,此ALSO也会终止从SCM事件触发构建的功能!
有什么方法可以阻止分支发现(分支索引)后触发生成,但是仍然可以通过SCM事件正常生成?
答案 0 :(得分:1)
这不是此功能-https://issues.jenkins-ci.org/browse/JENKINS-41980
抑制SCM触发器应抑制由ACM触发的所有构建 不论如何检测到SCM,都可以检测到SCM中的更改
答案 1 :(得分:1)
据我了解,发生这种情况是因为在设置“禁止自动SCM触发”时未读取管道定义。
因此,詹金斯将不知道您在管道中声明的所有触发器(SCM,上游...),直到您第一次运行该作业。
因此,如果您不希望由分支索引触发构建,请设置选项“禁止自动SCM触发” 如果您希望Jenkins知道您的管道,以便他可以对您的触发器做出反应,则不应设置“禁止自动SCM触发器”
答案 2 :(得分:1)
在 Jenkins 待办事项列表中有对此类功能的特性请求:JENKINS-63673 Allow configuring in NoTriggerBranchProperty which builds should be suppressed。我今天创建了一个拉取请求,因此将来它有可能成为 Branch API 插件的一部分。在此期间,您可以使用自定义版本 (see the build)。
如何使用 JobDSL 插件自动配置:
multibranchPipelineJob {
// ...
branchSources {
branchSource {
source {
// ...
}
strategy {
allBranchesSame {
props {
suppressAutomaticTriggering {
strategyId(2)
}
}
}
}
}
}
// ...
}
答案 3 :(得分:0)
您始终可以向管道中添加逻辑以中止分支索引原因。例如:
boolean isBranchIndexingCause() {
def isBranchIndexing = false
if (!currentBuild.rawBuild) {
return true
}
currentBuild.rawBuild.getCauses().each { cause ->
if (cause instanceof jenkins.branch.BranchIndexingCause) {
isBranchIndexing = true
}
}
return isBranchIndexing
}
调整逻辑以适合您的用例。
答案 4 :(得分:0)
我知道这篇文章很老,但是也许有人仍然有这个问题,首先您需要安装插件basic-branch-build-strategies:
如果您使用的是jenkins dsl:
buildStrategies {
buildAllBranches {
strategies {
skipInitialBuildOnFirstBranchIndexing()
}
}
}
答案 5 :(得分:0)
我们可以相应地修改 branch-api-plugin。 https://github.com/jenkinsci/branch-api-plugin
这里 src/main/java/jenkins/branch/OverrideIndexTriggersJobProperty.java 在这个文件中它决定触发构建的任务
这里我修改了函数,这样功能分支不会被触发,但仍会被添加到列表中。
默认情况下,它评估复选框 Suppress Automatic SCM trigger
@Extension
public static class Dispatcher extends Queue.QueueDecisionHandler {
private static final Logger LOGGER = Logger.getLogger(Dispatcher.class.getName());
@SuppressWarnings("rawtypes") // untypable
@Override
public boolean shouldSchedule(Queue.Task p, List<Action> actions) {
LOGGER.log(Level.INFO, "[TARUN_DEBUG] TASK NAME : "+ p.getName());
if(p.getName().startsWith("feature")||p.getName().startsWith("bugfix")){
return false;
}
else if(p.getName().startsWith("release")||p.getName().equals("master")||p.getName().startsWith("develop")||p.getName().startsWith("part of")||p.getName().startsWith("PR-")){
}
else{
LOGGER.log(Level.INFO, "[TARUN_DEBUG] NOT TRIGGERED "+p.getName());
return false;
}
for (Action action : actions) {
if (action instanceof CauseAction) {
for (Cause c : ((CauseAction) action).getCauses()) {
if (c instanceof BranchIndexingCause) {
if (p instanceof Job) {
Job<?,?> j = (Job) p;
OverrideIndexTriggersJobProperty overrideProp = j.getProperty(OverrideIndexTriggersJobProperty.class);
if (overrideProp != null) {
return overrideProp.getEnableTriggers();
} else {
return true;
}
}
}
}
}
}
return true;
}