Question

Trying to implement a jenkins plugin, which should display baselines under a specified VOB by using cleartool command cleartool lstpye -kind lbtype -s -inv \VOB but getting errors in command execution process (VOB is the input parameter). Don't know exactly where the problem is or if I am doing something wrong in the code. I will appreciate your suggestions.

Here is the code

public class MakeViewDefinition extends SimpleParameterDefinition{

private String vob;

public static String getVob(String vob) throws IOException{
    try{        
        String[] cmd = {"cmd.exe", "/C", "cleartool", "lstype", "-kind", "lbtype", "-s", "-inv", "\\", vob};
        Process p=Runtime.getRuntime().exec(cmd);
        BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        String output = "";
        while((line=reader.readLine()) != null){
            output +=line+ "\n";    
        }
        return output;
    }
    catch ( IOException ioe )  
    {  
        System.out.println("ERROR: " + ioe); 
    }
    return "WARNING: End of getVob()\n"; 
}

@DataBoundConstructor
public MakeViewDefinition(String name, String description, String vob){
    super(name, description);
    this.vob= vob;
}

protected static List<String> getList (String output){

    return getList(output);
}

 @Extension
 static public class DescriptorImpl extends ParameterDescriptor{
     @Override
     public String getDisplayName(){
         return Messages.MakeViewDefinition_DisplayName();
     }

     public FormValidation doCheckVob(@QueryParameter String vob){
         if (StringUtils.isBlank(vob)){
             return FormValidation.error(Messages.MakeViewDefinition_vob_empty());
         }
     return FormValidation.ok();
     }

     public FormValidation doTest(@QueryParameter String output) throws IOException{
         List<String> filelist = getList(getVob(output));
         if(filelist.isEmpty()){
             return FormValidation.ok("(No File matched)");
         }
         return FormValidation.ok(StringUtils.join(filelist, '\n'));
     }
 } 

@Override
public ParameterValue createValue(String value) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
    // TODO Auto-generated method stub
    return null;
}
}

config.jelly

<f:entry title="${%Name}" field="name">
    <f:textbox />
</f:entry>
<f:entry title="${%Description}" field="description">
    <f:textarea />
</f:entry>
<f:entry title="${%VoB Directory}" field="vob">
    <f:textbox />
</f:entry>
<f:validateButton
    method="test"
    title="${%List Files Now}"
    progress="${%Checking...}"
    with="vob"
/>

index.jelly

<f:entry title="${it.name}" description="${it.description}">
    <div name="parameter" description="${it.description}">
        <input type="hidden" name="name" value="${it.name}" />
        <j:scope>
            <j:set var="instance" value="${it.defaultParameterValue}" />
            <myF:staticSelect
                name="value"
                field="value"
                vob="${it.vob}"
            />
        </j:scope>
    </div>
</f:entry>

Here are error messages:

Caused by: java.lang.NullPointerException
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at de.bosch.MakeView.MakeViewDefinition.getVob(MakeViewDefinition.java:34)
at de.bosch.MakeView.MakeViewDefinition$DescriptorImpl.doTest(MakeViewDefinition.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:120)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:728)
... 69 more
Was it helpful?

Solution

First you need to make sure the vob is mounted (if you are using dynamic views), and your command should use "\\"+vob, not "\\", vob.

As mentioned here, a NPE means one of the arguments if null, which is the case if you enter the wrong name (like 'xxx' instead of \xxx.
If that is the case, you can skip the '\\' in your cmd array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top