配置块中带有脚本插件的 jenkins dsl 无法正常工作

jenkins dsl with scriptler plugin in configure block not working

我可以使用这里的 jenkins playground 创建一个作业 http://job-dsl.herokuapp.com/ xml 与手动创建作业的 config.xml 完全一样,但是当我 运行 作业的种子创建了下面脚本中的作业,但是我的配置块被完全忽略了。所需的插件已安装,我可以手动配置它,但我无法使用 DSL 进行配置。

这是我的 dsl 脚本。

def disabledAll = false;

def projects = [
    [name: 'test-job', description: 'Test Job', branch: 'develop', disabled: disabledAll]]

projects.each { project ->
    job(project.name) {
        disabled(project.disabled)


    description(project.description)
    keepDependencies(false)

    properties {

    }

authorization {
    permission('hudson.model.Item.Read:test')
    permission('hudson.model.Item.Workspace:test')
    permission('hudson.model.Item.Build:test')
}

parameters {
    stringParam('TAG', null, null)
}

steps() {
    shell('export BUILD_VERSION=${BUILD_VERSION} \nexport TAG=${TAG} \n #run grunt build \ncd /var/lib/jenkins/buildcode/ \n#grunt distribute --verbose --build=${BUILD_VERSION} --branch=${TAG} \ngrunt distribute --build=${BUILD_VERSION} --branch=${TAG}')
}


configure { 
    it / 'properties' / 'hudson.model.ParametersDefinitionProperty' / 'parametersDefinitions' << 'com.seitenbau.jenkins.plugins.dynamicparameter.scriptler.ScriptlerStringParameterDefinition' {
        name('BUILD_VERSION')
        description('Overall Build version')
        __uuid('1515be93-8945-4247-b0dc-798452187a2b')
        __remote(false)
        __scriptlerScriptId('lat_build_values.groovy')
    }

}


}

}

xml 输出:

<project>
    <actions></actions>
    <description>Test Job</description>
    <keepDependencies>false</keepDependencies>
    <properties>
        <hudson.security.AuthorizationMatrixProperty>
            <blocksInheritance>false</blocksInheritance>
            <permission>hudson.model.Item.Read:test</permission>
            <permission>hudson.model.Item.Workspace:test</permission>
            <permission>hudson.model.Item.Build:test</permission>
        </hudson.security.AuthorizationMatrixProperty>
        <hudson.model.ParametersDefinitionProperty>
            <parameterDefinitions>
                <hudson.model.StringParameterDefinition>
                    <name>TAG</name>
                    <defaultValue></defaultValue>
                </hudson.model.StringParameterDefinition>
            </parameterDefinitions>
            <parametersDefinitions>
                <com.seitenbau.jenkins.plugins.dynamicparameter.scriptler.ScriptlerStringParameterDefinition>
                    <name>BUILD_VERSION</name>
                    <description>Overall Build version seen in the Business Manager</description>
                    <__uuid>1515be93-8945-4247-b0dc-798452187a2b</__uuid>
                    <__remote>false</__remote>
                    <__scriptlerScriptId>lat_build_values.groovy</__scriptlerScriptId>
                </com.seitenbau.jenkins.plugins.dynamicparameter.scriptler.ScriptlerStringParameterDefinition>
            </parametersDefinitions>
        </hudson.model.ParametersDefinitionProperty>
    </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>
        <hudson.tasks.Shell>
            <command>export BUILD_VERSION=${BUILD_VERSION} 
export TAG=${TAG} 
 #run grunt build 
cd /var/lib/jenkins/buildcode/ 
#grunt distribute --verbose --build=${BUILD_VERSION} --branch=${TAG} 
grunt distribute --build=${BUILD_VERSION} --branch=${TAG}</command>
        </hudson.tasks.Shell>
    </builders>
    <publishers></publishers>
    <buildWrappers></buildWrappers>
</project>

知道我需要做什么才能在作业中实际创建配置吗?

元素名称有错别字。是 parameterDefinitions 而不是 parametersDefinitions

这应该有效:

job('example') {
  configure { 
    it / 'properties' / 'hudson.model.ParametersDefinitionProperty' / 'parameterDefinitions' << 'com.seitenbau.jenkins.plugins.dynamicparameter.scriptler.ScriptlerStringParameterDefinition' {
      name('BUILD_VERSION')
      description('Overall Build version')
      __uuid('1515be93-8945-4247-b0dc-798452187a2b')
      __remote(false)
      __scriptlerScriptId('lat_build_values.groovy')
    }
  }
}