WorkflowJob getDescriptor Null

13 views
Skip to first unread message

Shaun Thompson

unread,
Aug 25, 2017, 12:56:40 PM8/25/17
to Jenkins Developers
I'm currently trying to create Workflow job from my plugin using the following code.

Jenkins.getInstance().createProject(WorkflowJob.class, SomeClass.class.getSimpleName());

It fails to find the descriptor when running the following

public Descriptor getDescriptor(Class<? extends Describable> type) {
        for( Descriptor d : getExtensionList(Descriptor.class) )
            if(d.clazz==type)
                return d;
        return null;
    }

What's seems odd to me is that the tests supplied with the workflow plugin show the same issue when I run it locally.


Any idea on what's going on?

Mark Waite

unread,
Aug 25, 2017, 1:09:46 PM8/25/17
to Jenkins Developers
You may need to add a test dependency on the workflow class (or classes) which provide that descriptor.

I added pipeline tests to a fork of the hello-world-plugin and had to add several test dependencies.

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/a762da27-0cf3-4dd7-98d2-09df23bff997%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jesse Glick

unread,
Aug 25, 2017, 3:23:38 PM8/25/17
to Jenkins Dev
On Fri, Aug 25, 2017 at 12:52 PM, Shaun Thompson <sth...@gmail.com> wrote:
> What's seems odd to me is that the tests supplied with the workflow plugin
> show the same issue when I run it locally.
>
> Any idea on what's going on?

Something is seriously wrong in your test environment. Close your IDE,
open a command shell, and try

mvn clean test

Or, for paranoid Linux users,

alias dockermvn='docker run -v ~/.m2:/var/maven/.m2 -ti --rm --name
mvn -u $(id -u):$(id -g) -e MAVEN_CONFIG=/var/maven/.m2 -v
"$PWD":/usr/src/mymaven -w /usr/src/mymaven maven:3.5.0-jdk-8 mvn
-Duser.home=/var/maven'
dockermvn clean test

Shaun Thompson

unread,
Aug 28, 2017, 3:11:08 PM8/28/17
to Jenkins Developers

From the command line it works.  It looks like I'll have to dig into the extensions bit and see how this is getting setup.

Shaun Thompson

unread,
Aug 28, 2017, 3:24:17 PM8/28/17
to Jenkins Developers
To answer my own question, the issue was that I was trying to access the Workflow job before Jenkins had properly loaded the extension.

The following change allowed me to create a Workflow job dynamically
@Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED)
    public void initProject() {
        try {
            for (final WorkflowJob job : Util.createSubList(jenkins().getItemMap().values(), WorkflowJob.class)) {
                if (job.getDisplayName().equalsIgnoreCase(projectName())) {
                    workflowJob = job;
                }
            }
            if (workflowJob == null) {
                workflowJob = jenkins().createProject(WorkflowJob.class, ReleaseManagementPlugin.class.getSimpleName());
            }
        } catch (final Exception ex) {
            throw ReleaseException.builder().with(ex).build();
        }
    }


Reply all
Reply to author
Forward
0 new messages