我试图用参数创建userInput并尝试在管道中回显它,但是在尝试使其工作时遇到了java.lang.NullPointerException
。
这是Jenkins管道脚本:
def userInput
try {
userInput = input(
id: 'Verification', message: 'Waiting for verification',parameters: [
[$class: 'TextParameterDefinition', description: 'action', name: 'action']
])
} catch(err) { // input false
def user = err.getCauses()[0].getUser()
echo 'Aborted by: [${user}]'
currentBuild.result = 'ABORTED'
error('Verification failure')
}
echo userInput
echo userInput.action
echo 'Verified'
在Java网站中:
URL url = new URL ("http://testing:1234/job/abc/job/abc-application/123/input/Verification/proceedEmpty?action=TestAction");
String authStr = authUser + ":" + authKey;
String encoding = DatatypeConverter.printBase64Binary(authStr.getBytes("utf-8"));
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + encoding);
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
OutputStream os = connection.getOutputStream();
//String data = "{\"parameter\": [{\"name\":\"action\", \"value\":\"TestUser\"}]}";
//os.write(data.toString().getBytes("UTF-8"));
os.close();
content = connection.getInputStream();
in = new InputStreamReader(content);
br = new BufferedReader(in);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
我希望管道可以正常处理,但是出现以下错误:
Input requested
Approved by admin
[Pipeline] echo
null
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.NullPointerException: Cannot get property 'action' on null object
我希望管道可以继续进行,输出应该是:
Input requested
Approved by admin
[Pipeline] echo
TestAction
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
...