Jenkins Job DSL:如何在Configure块中构建特定节点



我特别想要的是防止在Flexible Publish部分执行某些步骤。我使用字符串(不)匹配的条件,并且我不希望在检查失败后执行某些内容。

手动配置时,预期步骤如下所示:预期的生成后步骤

由于我在Jenkins Jobs DSL API中没有找到合适的方法,我尝试使用Configure块来复制它。引用中说,我可以将"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中也没有生成。相反,我有重复的节点,似乎"node"被解释为"project",并且总是放在根上。

<!-- 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>

我已经通过Job DSL版本1.40在Playground中检查了这个例子,但我的jenkins中的1.39给出了相同的结果。

我做错了什么?

谢谢。

UPD我按照SevenEleven的建议在下面放置了配置块,它几乎起到了帮助作用。runner节点现在位于正确的位置,但仍然是重复的。

<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>

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

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-块放在下面,而不是放在发布者配置中:

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') {
        }
    }
}

相关内容

  • 没有找到相关文章

最新更新