4

I've been scratching my head over this for the past 2 days but haven't been able to find a solution...

Basically, I have a plugin that has two dropdown lists ( jelly tags). One of them is be filled with all available project types, the other one should get filled with builders which are applicable to the previously selected project type. I'm building the plugin against Jenkins version 1.578.

Here's my config jelly:

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson"
  xmlns:f="/lib/form">

  <f:entry title="Projectname" field="projectName">
    <f:textbox />
  </f:entry>
  <f:entry title="Build project after creation?" field="runProjectAfterCreation">
    <f:checkbox />
  </f:entry>

  <f:entry title="Project configuration">
    <f:entry title="Project / Job Type" field="projectType">
      <f:select default="noTypeSelected" name="projectType"/>
    </f:entry>

    <f:entry title="Build Steps">
      <f:repeatable var="buildSteps" items="buildSteps" minimum="1">
        <table width="100%" bgcolor="#EEEEEE">
          <div width="100%">
            <f:entry field="buildStepType">
              <f:select default="noBuildStepSelected" />
              <f:repeatableDeleteButton value="Delete Build Step" />
            </f:entry>
          </div>
        </table>
      </f:repeatable>
    </f:entry>

  </f:entry>
</j:jelly>

The projectType dropdown gets filled just fine with this function:

public ListBoxModel doFillProjectTypeItems() {
    ListBoxModel items = new ListBoxModel();
    items.add( "Bitte Projekttyp wählen", "noTypeSelected" );
    for ( TopLevelItemDescriptor tliDescriptor : getAvailableJobTypes() ) {
        items.add( tliDescriptor.getDisplayName(), tliDescriptor.getId() );
    }
    return items;

}

But the buildStepType doesn't.

public ListBoxModel doFillBuildStepTypeItems( @QueryParameter( "../projectType" ) final String projectType ) {
    ListBoxModel items = new ListBoxModel();
    if ( ( !projectType.equals( "noTypeSelected" ) ) && ( !projectType.equals( "hudson.maven.MavenModuleSet" ) ) ) {
        try {
            for ( BuildStepDescriptor<? extends Builder> buildStep : getAvailableBuilders( (Class<? extends AbstractProject<?, ?>>) Class
                    .forName( projectType ).asSubclass( AbstractProject.class ) ) ) {
                items.add( buildStep.getDisplayName(), buildStep.getId() );
            }
        } catch ( ClassNotFoundException ex ) {
            throw new RuntimeException( ex );
        }
        // Maven projects will throw a java.lang.ClassNotFoundException
    } else if ( projectType.equals( "hudson.maven.MavenModuleSet" ) ) {
        items.add( "Mavenprojects are not supported!", "mavenSelected" );
    } else {
        items.add( "Choose project type first, please!", "noProjectType" );
    }
    return items;
}

A java.lang.reflect.InvocationTargetException is caused by a NullPointerException at the following line:

if ( ( !projectType.equals( "noTypeSelected" ) ) && ( !projectType.equals("hudson.maven.MavenModuleSet" ) ) )

because projectType is null. Apparently the @QueryParameter doesn't fetch the selected value from the first dropdown. It does "know that it's there" though, since the function gets called when I select a new project type.

Does someone know a fix to this problem?

Nimelrian
  • 1,726
  • 13
  • 23

1 Answers1

3

Hope this answer is not too late.

You can see

https://github.com/jenkinsci/jenkins/blob/jenkins-1.578/core/src/main/java/hudson/RelativePath.java

And here is the usage:

public ListBoxModel doFillBuildStepTypeItems( 
@QueryParameter("projectType") @RelativePath("..") 
final String projectType ) {...}
Theo
  • 31
  • 3