Jenkins Plugin cannot get called from the pipeline with new syntax

36 views
Skip to first unread message

prasad...@globallogic.com

unread,
Feb 22, 2019, 5:25:17 PM2/22/19
to Jenkins Users
I have developed a custom Jenkins plugin which extends Recorder and implements SimpleBuildStep. I was calling this plugin using the syntax:

pipeline {
    agent any
    stages {
        stage('Build and Run Tests') {
            steps {
                step([$class : 'TestClass', name: 'admin', lastname: 'admin', endPoint:'http://localhost:8080/', file:'path/to/myfile.txt'])
            }
        }
    }
}

With this the plugin is executed, but now my requirement is to call this plugin with the different pipeline syntax which is our primary requirement. The required syntax is as follows:

pipeline {
    agent any
     stages {
         stage('Build and Run Tests') {
              steps {
                   
TestClass name:'admin' lastname: 'admin' endPoint: 'http://localhost:8080/', file:'path/to/myfile.txt'
              }
          }
     }
}

But I am not able to call the same plugin with the above syntax. Can anyone please help me?

Richard Bywater

unread,
Feb 24, 2019, 1:49:56 AM2/24/19
to jenkins...@googlegroups.com
You need to define a Symbol in your plugin.  See Defining Symbols section at https://jenkins.io/doc/developer/plugin-development/pipeline-integration/

Richard

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/db5c1523-75e2-4969-ba26-54dede193291%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

prasad...@globallogic.com

unread,
Feb 25, 2019, 7:16:55 AM2/25/19
to Jenkins Users
Hello,

I have created a Symbol in TestRunPublisher for descriptor. The code now looks like following:


public class TestUploader extends Publisher implements SimpleBuildStep {
    private final String name;
    private final String password;
//getters are there for above variables.
    @DataBoundConstructor
    public TestUploader (String name, String password){
//set the data to class members.
    }
@Symbol("TestUploader")
    @Extension
    ublic static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
public DescriptorImpl () {
            load();
        }
    }
          public boolean isApplicable (Class<? extends AbstractProject> aClass) {return true;}

public String getDisplayName () {return "TestUploader";}

@Override
public boolean configure (StaplerRequest req, JSONObject formData) throws FormException {
    save();
    return super.configure(req, formData);
}
    }

I think I am missing out on something.

Richard Bywater

unread,
Feb 25, 2019, 12:59:25 PM2/25/19
to jenkins...@googlegroups.com
You'll need to provide some idea of what error/behaviour you are seeing as otherwise it's hard to help point you in the right direction.

Richard

prasad...@globallogic.com

unread,
Feb 26, 2019, 7:36:13 AM2/26/19
to Jenkins Users
Thanks Richard,

I have defined the Symbol using  @Symbol("TestUploader") annotation but it was not working. Now that I have changed the parameter of annotation to @Symbol("testUploader"), it is working with the following syntax.

pipeline {
    agent any
     stages {
         stage('Build and Run Tests') {
              steps {
                   testUploader name:'admin', lastname: 'admin', endPoint: 'http://localhost:8080/', file:'path/to/myfile.txt'
              }
          }
     }
}


Thanks for the help :)
Reply all
Reply to author
Forward
0 new messages