尝试实现jenkins插件,该插件应使用cleartool命令VOB
在指定的cleartool lstpye -kind lbtype -s -inv \VOB
下显示基线,但在命令执行过程中会出错(VOB
是输入参数)。不确切知道问题出在哪里,或者我是否在代码中做错了什么。感谢您的建议。
这是代码
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"
/>
索引胶
<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>
这是错误消息:
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
最佳答案
首先,您需要确保已安装VOB(如果使用的是动态视图),并且您的命令应使用"\\"+vob
,而不是"\\", vob
。
与mentioned here一样,NPE表示参数中的一个(如果为null),如果输入的名称错误(例如使用“ xxx
”而不是\xxx
),情况就是这样。
在这种情况下,您可以跳过\\
数组中的“ cmd
”。