1
Jenkinsの残りのAPIを使用してJenkinsのURLを使用してジョブの設定を変更しようとしています。Rest APIを使用してJenkinsジョブ設定を更新中にエラーが発生しました
私はジェンキンスを再起動せずに自分の仕事を更新できるように変更を提案してください。私はJenkins 2.19.4を使用しています。 jenkinsの設定があります。これはjenkins config.xmlに接続するのをブロックしていますか、またはJavaコードに問題がありますか?
try
{
String fileDir = "D:\\"; // upload directory
String fileName = "config.xml";
URL url = new URL("http://myjenkins/job/test/config.xml"); // Jenkins URL localhost:8080, job named 'test'
String user = "username"; // username
String pass = "password"; // password or API token
String authStr = user +":"+ pass;
String encoding = DatatypeConverter.printBase64Binary(authStr.getBytes("utf-8"));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(10000);
connection.setConnectTimeout(15000);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty ("Authorization", "Basic " + encoding);
try
{
String filePath = "D:\\config.xml";
FileInputStream inputStream = new FileInputStream(new File(filePath));
FileReader fr = new FileReader(new File(filePath));
BufferedReader br = new BufferedReader(fr);
String sCurrentLine;
System.out.println(sCurrentLine = br.readLine());
OutputStream os = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
while ((sCurrentLine = br.readLine()) != null) {
//System.out.println("not going inside!!!!");
writer.write(sCurrentLine);
System.out.println(sCurrentLine);
}
writer.flush();
writer.close();
os.close();
int responseCode=connection.getResponseCode();
System.out.println(responseCode);
}
catch(Exception e)
{
e.printStackTrace();
}
}
catch(Exception e)
{
e.printStackTrace();
}
エラーは何ですか? – Arran
java.io例外で403 HTTP応答が返されています –
403サーバーが要求を理解したが、それを承認することを示唆しています...ユーザー/ pwdが正しいかどうかを確認し、期待されるエンコードで渡されます –