0

I am able to create a job using the jenkins playground here http://job-dsl.herokuapp.com/ to where the xml is exactly like the config.xml of a manually created job, but when i run the seed for the job the job in the script below is created, but my configure block is completely ignored. The plugin needed is installed, i can configure this manually, but i cannot configure it using the DSL.

here is my dsl script.

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

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

Any idea what i need to do for this to actually create the config in the job?

1 Answers1

0

There is a typo in an element name. It's parameterDefinitions not parametersDefinitions.

This should work:

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')
    }
  }
}
daspilker
  • 8,154
  • 1
  • 35
  • 49