Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-28408

Jenkins can't load extension ContextExtensionPoint if dependency is optional

XMLWordPrintable

      As in tutorial:
      https://github.com/jenkinsci/job-dsl-plugin/wiki/Extending-the-DSL

      extend:

      @Extension(optional = true)
      public class AquaPluginJobDslExtension extends ContextExtensionPoint {
      
          @DslExtensionMethod(context = StepContext.class)
          public Object aqua(Runnable closure) {
              AquaContext context = new AquaContext();
              executeInContext(closure, context);
      
              return new AquaPluginBuilder(
                      context.getPacks(),
                      context.getRunType(),
                      context.getLogLevel().getName(),
                      context.getTimeout(),
                      context.getUnits().name(),
                      context.getDelayPollSec()
              );
          }
      }
      

      with dependency:

      <dependency>
                  <groupId>org.jenkins-ci.plugins</groupId>
                  <artifactId>job-dsl</artifactId>
                  <version>1.34</version>
                  <optional>true</optional>
      </dependency>
      

      Then with job-dsl 34 installed do in jenkins script console:

      import javaposse.jobdsl.plugin.ContextExtensionPoint;
      
      Jenkins.instance.refreshExtensions();
      println(Jenkins.instance.getExtensionList(ContextExtensionPoint.class))
      

      prints "[]"

      With dependency <optional>false</optional>

      it prints:
      [com.example.dsl.AquaPluginJobDslExtension@2ee05de3]

      Okay,
      do the same with token macro plugin:

       <dependency>
                  <groupId>org.jenkins-ci.plugins</groupId>
                  <artifactId>token-macro</artifactId>
                  <version>1.10</version>
                  <optional>true</optional>
              </dependency>
      
      @Extension(optional = true)
      public class TokenMExt extends DataBoundTokenMacro {
          @Override
          public String evaluate(AbstractBuild<?, ?> abstractBuild, TaskListener taskListener, String s) throws MacroEvaluationException, IOException, InterruptedException {
              return null;
          }
      
          @Override
          public boolean acceptsMacroName(String s) {
              return false;
          }
      }
      

      in console:

      import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro;
      
      println(Jenkins.getInstance().getExtensionList(DataBoundTokenMacro.class))
      

      prints:
      [..., org.jenkinsci.plugins.tokenmacro.impl.PropertyFromFileMacro@11786964, com.example.dsl.TokenMExt@13a9b76f]

            daspilker Daniel Spilker
            lanwen Kirill Merkushev
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: