Re: How to create/update Jenkins job via REST API in Java?

2022-04-11 Thread 'Daniel Beck' via Jenkins Users
On Mon, Apr 4, 2022 at 11:13 AM Jon Brohauge  wrote:

> Whenever I try to POST a job, using a Basic Authentication with the
> “username:password” base64 encoded, I get a 403.
>

Crumbs are session-specific since 2.176.2:
https://www.jenkins.io/doc/upgrade-guide/2.176/#upgrading-to-jenkins-lts-2-176-2

Either use an API token, or record the `Set-Cookie` response header and it
the same session ID with every subsequent request.


> Whenever I try to POST a job, using a Basic Authentication with the
> “username:apitoken” base64 encoded, I get a 500. The apitoken has been
> handmade just for this test.
>

The reason for the HTTP 500 is something the logs on Jenkins should tell
you. My guess is you forgot to set `Content-Type: text/xml` as documented
in `/job/whatever/api/`.

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAMo7PtK7WUYUD5AV%2BQr8MvdJ8fjJrJCa5%2B4dNwKedTs_a0OLxA%40mail.gmail.com.


Re: How to create/update Jenkins job via REST API in Java?

2022-04-04 Thread Ivan Fernandez Calvo
if you want to manage your jobs using the API are some tools that make that 
work Jenkin Job Builder 
, also you can 
manage your Jobs and configuration using Jenkins configuration as Code 

 
and JobDSL plugin 

El lunes, 4 de abril de 2022 a las 11:13:34 UTC+2, jonbr...@gmail.com 
escribió:

> Hi everyone,
>
>  
>
> I’m trying to create/update a Jenkins job via the REST API. I can 
> successfully retrieve a crumb, so I know that my username/password 
> combination works.
>
> Whenever I try to POST a job, using a Basic Authentication with the 
> “username:password” base64 encoded, I get a 403.
>
> Whenever I try to POST a job, using a Basic Authentication with the 
> “username:apitoken” base64 encoded, I get a 500. The apitoken has been 
> handmade just for this test.
>
>  
>
> I have tried to use the example posted in Cloudbees Support (
> https://support.cloudbees.com/hc/en-us/articles/226835367-How-to-update-job-config-files-using-the-REST-API-and-Java-
> )
>
> The project source files are located here: 
> https://github.com/Topdanmark/jenkins-job-rest-api
>
>  
>
> The username, password, and server have been redacted for obvious reasons.
>
>  
>
> Any pointers are appreciated. A quick heads up. The project must be able 
> to run on Java8 on Windows, due to legacy requirements.
>
>
> Regards,
>
> Jon Brohauge
>

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/afe9afac-37ee-41dc-b854-11d3cc4e31f1n%40googlegroups.com.


How to create/update Jenkins job via REST API in Java?

2022-04-04 Thread Jon Brohauge
Hi everyone,



I’m trying to create/update a Jenkins job via the REST API. I can
successfully retrieve a crumb, so I know that my username/password
combination works.

Whenever I try to POST a job, using a Basic Authentication with the
“username:password” base64 encoded, I get a 403.

Whenever I try to POST a job, using a Basic Authentication with the
“username:apitoken” base64 encoded, I get a 500. The apitoken has been
handmade just for this test.



I have tried to use the example posted in Cloudbees Support (
https://support.cloudbees.com/hc/en-us/articles/226835367-How-to-update-job-config-files-using-the-REST-API-and-Java-
)

The project source files are located here:
https://github.com/Topdanmark/jenkins-job-rest-api



The username, password, and server have been redacted for obvious reasons.



Any pointers are appreciated. A quick heads up. The project must be able to
run on Java8 on Windows, due to legacy requirements.


Regards,

Jon Brohauge

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAKob%2BgMv_kJ%3DApBhgx0dx-aDz3CTUPMYsu8uSkVu2xkh1h_YVQ%40mail.gmail.com.