1

I am trying to build a python script that will build jobs externally but when I am executing it, throws 403 forbidden error for build jobs call other get APIs are working fine. Below is the python snippet.

j=jenkins.Jenkins('http://localhost:8080/login?from=%2F', 'admin', 'admin@123' )

j.get_jobs();

print(j.jobs_count());

print(j.get_jobs());

j.build_job('demo1');

Jenkins details: I am able to create & build jobs from UI successfully. My Jenkins version is 2.237.

Other settings.

  • logged in user can do anything. Csrf protection is disabled. On the other hand my friend having the same script and version of Jenkins is able to build job.

1 Answer 1

1

As recommended by Jenkins (>2.2xx) you may benefit by creating an API token for the user, I did so, to trigger Jenkins job in my local Jenkins server from NODEJS code.

Please refer below for further clarification:

  1. https://www.jenkins.io/doc/book/system-administration/authenticating-scripted-clients/#shell-with-curl
  2. https://www.jenkins.io/doc/book/using/remote-access-api/#RemoteaccessAPI-CSRFProtection

And for details: https://www.jenkins.io/doc/book/managing/security/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.