gpt4 book ai didi

Jenkins 作业 DSL : how to build particular node in Configure block?

转载 作者:行者123 更新时间:2023-12-02 22:03:09 24 4
gpt4 key购买 nike

我想要的具体事情是防止在“灵活发布”部分中执行某些步骤。我使用字符串(不)匹配的条件,并且我不希望在检查失败后执行某些操作。

手动配置,预期步骤如下所示: Expected postbuild step

由于我在Jenkins Jobs DSL API中没有找到合适的方法我尝试使用配置 block 重现它。该引用资料说,我可以使用“project”作为作业的根元素,使用“node”作为特定节点来向其附加子元素。它还表示,如果指向的节点存在,则不会再次创建新节点。这是我的配置:

job("flexible_condition") {

publishers {

flexiblePublish {
configure { node ->
node / publishers /
'org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher' << 'runner'(class:
'org.jenkins_ci.plugins.run_condition.BuildStepRunner$DontRun')
}

condition {
not { stringsMatch('string_placeholder', '', false) }
}

publisher {
debianPackage('common') {
commitMessage('new feature')
}
}

publisher {
git {
pushOnlyIfSuccess(true)
branch('origin', 'master')
}
}
}
}
}

尽管引用了所需的 xml,但我的 Jenkins 和 Playground 中都没有生成。我已经复制了节点,并且似乎“节点”被解释为“项目”并且始终放在根目录中。

<!-- 1. flexible_condition -->
<project>
<actions></actions>
<description></description>
<keepDependencies>false</keepDependencies>
<properties></properties>
<scm class='hudson.scm.NullSCM'></scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers class='vector'></triggers>
<concurrentBuild>false</concurrentBuild>
<builders></builders>
<publishers>
<org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher>
<runner class='org.jenkins_ci.plugins.run_condition.BuildStepRunner$DontRun'></runner>
</org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher>
<org.jenkins__ci.plugins.flexible__publish.FlexiblePublisher>
<publishers>
<org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher>
<condition class='org.jenkins_ci.plugins.run_condition.logic.Not'>
<condition class='org.jenkins_ci.plugins.run_condition.core.StringsMatchCondition'>
<arg1>string_placeholder</arg1>
<arg2></arg2>
<ignoreCase>false</ignoreCase>
</condition>
</condition>
<publisherList>
<ru.yandex.jenkins.plugins.debuilder.DebianPackagePublisher>
<repoId>common</repoId>
<commitMessage>new feature</commitMessage>
<commitChanges>true</commitChanges>
</ru.yandex.jenkins.plugins.debuilder.DebianPackagePublisher>
<hudson.plugins.git.GitPublisher>
<configVersion>2</configVersion>
<pushMerge>false</pushMerge>
<pushOnlyIfSuccess>true</pushOnlyIfSuccess>
<forcePush>false</forcePush>
<tagsToPush></tagsToPush>
<branchesToPush>
<hudson.plugins.git.GitPublisher_-BranchToPush>
<targetRepoName>origin</targetRepoName>
<branchName>master</branchName>
</hudson.plugins.git.GitPublisher_-BranchToPush>
</branchesToPush>
</hudson.plugins.git.GitPublisher>
</publisherList>
<runner class='org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail'></runner>
</org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher>
</publishers>
</org.jenkins__ci.plugins.flexible__publish.FlexiblePublisher>
</publishers>
<buildWrappers></buildWrappers>
</project>

我一直在 Playground 中通过 Job DSL 版本 1.40 检查此示例,但我的 jenkins 中的 1.39 给出了相同的结果。

我做错了什么?

谢谢。

UPD 我已按照 SevenEleven 的建议将配置 block 放在下面,它几乎有所帮助。运行者节点现在位于正确的位置,但仍然是重复的。

<publishers>
<org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher>
<condition .../>
<publisherList>
...
</publisherList>
<runner class='org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail'></runner>
<runner class='org.jenkins_ci.plugins.run_condition.BuildStepRunner$DontRun'></runner>
</org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher>
</publishers>

UPD 2 尽管 xml 中有两行不同的行,但较新的运行程序会替换生成作业中的默认运行程序。所以我得到了预期的结果。谢谢。

UPD 3。耶!发现现在可以简单地使用 JobDSL 语法并且它可以工作。

publishers {

flexiblePublish {
conditionalAction {
condition {
not { stringsMatch('string_placeholder', '', false) }
}

publishers {
debianPackage('common') {
commitMessage('Automatic Commit')
}
git {
pushOnlyIfSuccess(true)
branch('origin', '$GIT_BRANCH')
}
}

runner('DontRun')
}
}
}

最佳答案

编辑配置,您必须将configure block 放在下面,而不是放在发布者配置中:

job("flexible_condition") {
publishers {
flexiblePublish {
//...
}
}

configure {
it / publishers / 'org.jenkins__ci.plugins.flexible__publish.FlexiblePublisher' / publishers / 'org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher' / 'runner'(class:'org.jenkins_ci.plugins.run_condition.BuildStepRunner$DontRun') {
}
}
}

关于 Jenkins 作业 DSL : how to build particular node in Configure block?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34161891/

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