Have you tried with the command line?
- 
https://support.cloudbees.com/hc/en-us/articles/218353308-How-to-update-job-config-files-using-the-REST-API-and-cURL

Cheers

On Tuesday, 20 December 2016 12:39:20 UTC, Kruti Vyas wrote:
>
> I am trying to change the configuration of a job using Jenkins' rest api 
> using my java code but my code is not able to connect to jenkins url. My 
> code is showing 403 http response while connecting. Please suggest me the 
> changes so that I can update my job without restarting the jenkins. I am 
> using jenkins 2.19.4 version.
>
> try
>     {
>         String fileDir = "D:\\"; // upload directory
>           String fileName = "config.xml";
>           URL url = new URL("http://myjenkins/job/test/config.xml 
> <http://www.google.com/url?q=http%3A%2F%2Fmyjenkins%2Fjob%2Ftest%2Fconfig.xml&sa=D&sntz=1&usg=AFQjCNGkzB0j8xvrM0G3QL6Z2HvuEHg-4Q>");
>  // 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();
>     }
>
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/924e1531-c783-46d2-9f17-723c51d74a03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to