Jenkins doesn't allow my build token - jenkins

I have set up a build token so that I can remotely trigger jobs on a jenkins that is setup with authentication.
However, when I try to use curl then it tries to redirect me to the login page.

In this case Jenkins path based authorization is not allowing you to get to that URL, even though you have a token for it.
Try the build root token plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin
This gives a different URL pattern that bypasses this, so you can trigger it from curl.

Related

remotely trigger job with API token

I want to remotely trigger jenkins jobs so i am using below command
curl -X POST https://svc-pro-jenkins:PASSWORD#jenkins.xxx.org.xx/job/folder_1/create_s3/builrWithParameters?env=prod
Now this works fine when i try this in dev jenkins as there i am passing API token not password.
But in production Jenkins security team is not allowing to create API token and when i use password i get below error.
HTTP 403 No valid crumb was included in request
Is there any way i can trigger job without creating API token?

SVN post commit hook is giving 403 forbidden while triggering Jenkins job

I am trying to implement my post commit hook from my SVN repo to trigger one Jenkins job for my spring boot microservice deployment. But when I am committing code change, its committing to SVN repository. But its not triggering Jenkins job and giving error like 403 forbidden and it showing post commit hook failed with error code 8 on dialog box,
I am getting error like the following:
My post commit hook file post-commit like the following (I was removed post-commit.tmpl and created new post-commit file and added content here):
And My Jenkins freestyle jobs like the following:
NB: Code change are successfully committing to SVN repository. Problem is when triggering the Jenkins job.
Have I made a mistake in any of my implementation?
Maybe you hit the CSRF (Cross Site Request Forgery) Jenkins protection.
CSRF protection uses a token (called crumb in Jenkins) that is created
by Jenkins and sent to the user. Any form submissions or similar
action resulting in modifications, like triggering builds or changing
configuration, requires that the crumb be provided.
Requests sent using the POST method are subject to CSRF protection in Jenkins >and generally need to provide a crumb.
If you have administrator permissions, you can configure CSRF Protection through Manage Jenkins » Configure Global Security » CSRF Protection.
If you authenticate your API calls with a username and a user API token then a crumb is not required from Jenkins 2.96. So you can:
Generate API token from Jenkins (admin permissions needed).
Then use the API token instead of password for your calls.
Reference:
https://www.jenkins.io/doc/book/security/csrf-protection/
Jenkins : Error 403 No valid crumb was included in the request : From TFS
https://support.cloudbees.com/hc/en-us/articles/219257077-CSRF-Protection-Explained
Jenkins: 403 No valid crumb was included in the request
This is probably a permission issue. See the subversion plugin documentation:
For this to work, your Jenkins has to allow anonymous read access (specifically, "Job > Read" access) to the system. If access control to your Jenkins is more restrictive, you may need to specify the username and password, depending on how your authentication is configured.

Gitlab Jenkins Webhook executed successfully but returned HTTP 403 (Authentication required)

My WebHook was successful but jenkins does not build the project.
I checked the gitLab logs where it appears that the weebhook received a 200 response from jenkins
Status 200 WebHook
Check first if this is similar to jenkinsci/gitlab-plugin/issue 375:
You can either add a special user in Jenkins for this and configure the Webhook in GitLab accordingly or
you can uncheck the checkbox "Enable authentication for '/project' end-point" in the GitLab section of the global Jenkins configuration. But this should be unchecked by default.
Better, from Jun Young Lee:
You can set Secret Token as well and I think this method is better than two other options since no credential exposed or no too open policy.
The OP Alejandro Herrera adds in the comments
I am using LDAP for authentication so it doesn't work with the token.
But I already fixed it: I simply added the authentication parameters in the url like this: https://USERNAME:PASSWORD#Serverjenkins.com/github-webhook

Webhook for Jenkins without credentials in URL

I've got a webhook setup in GitLab to detect whenever changes are pushed to the project repo. This works as needed, however the URL in use contains my Jenkins credentials and I'd like to make this more secure. e.g.:
https://username:password#jenkins.url.com/project/git-project
Is there a way to generate a token of sorts in Jenkins instead of providing my username and password?
There are access tokens in GitLab, you can use it. From Jenkins part, you can install GitLab plugin and then add new credentials for SSH and GitLab API Token. Please see this and this for more details.

How to start Jenkins build remotely with cloudbees authentication enabled

How to start Jenkins build remotely with cloudbees authentication enabled?
Please let me know the command to start it from a script or throw commang like wget/curl
You can POST to https://accountname.ci.cloudbees.com/job/jobname/build passing your CloudBees username (typically an email address) and Jenkins API token (see /me/configure) for BASIC authentication.
But if you would rather not keep your full credentials in a script, you can pick an arbitrary token and configure that in the job definition, in which case POSTing to build?token=… without authentication will schedule a build. In the usual case that your Jenkins instance is not visible to anonymous users, this will not work (since the whole URL space is blocked), in which case the Build Token Root plugin may be used to accomplish the same thing.

Resources