remotely trigger job with API token - jenkins

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?

Related

Remote Trigger Jenkins pipeline enabled with Single sign-on authentication

Requirement: Remote trigger Jenkins pipeline with and without parameters from my desktop using curl.
Jenkins Authentication: The Jenkins authentication is of a Single sign-on and can login successfully with my AD user name and I'm part of appropriate AD group that let me login which has admin level privilege. This user also has an API token generated to use with the command line to trigger the Jenkins pipeline remotely.
Test Pipeline configuration: Under Build Triggers, enabled "Trigger builds remotely" and an authentication token being used.
Commands: Executed the following commands from my desktop
curl -vk --user <AD user name>:<password> http://jenkinsurl/job/job-name/build?token=TOKEN
curl -vk --user <AD user name>:<password> http://jenkinsurl/job/job-name/buildWithParameters?token=TOKEN
curl -vk --user <AD user name>:<User API token generated on Jenkins> http://jenkinsurl/job/job-name/build?token=TOKEN
curl -vk --user <AD user name>:<User API token generated on Jenkins> http://jenkinsurl/job/job-name/buildWithParameters?token=TOKEN
Issue: HTTP Error 401 Unauthorized (Same error output for all the above commands)
Note: I can successfully run the above commands on a local Jenkins that I am running with Docker for windows on my desktop and trigger the pipeline remotely but there is no SSO authentication on this Jenkins and using the Jenkins default admin user for testing.
Can someone suggest me the steps or configurations required to trigger a remote pipeline(from command line) which has single sign-on enabled? Not sure what is missing in my setup.

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.

BitBucket Webhook gives Crumb issues while posting to Jenkins

I am trying to setup webhook from Bitbucket to Jenkins but it is failing while testing them crumb issues. This Jenkins is deployed to Kubernetes 1.17 and Jenkins is the latest image 2.249.1 . Even from PostMan I am getting the same issue. I know there is something wrong in Jenkins Setup only.
Error :
Error 403 No valid crumb was included in the request
HTTP ERROR 403 No valid crumb was included in the request
Assuming you are triggering the job as a pre-push script, if its throwing crumb errors, you need to create personalized API token within Jenkins and would need that to be embedded in the API call from Bitbucket to Jenkins.
Please refer this article for generating a token - https://support.cloudbees.com/hc/en-us/articles/115003090592-How-to-re-generate-my-Jenkins-user-token

How to automate release and staging phases with token using Jenkins and Artifactory?

I want to automate the Artifactory release and staging in jenkins job.
I got this curl command,
curl -X GET "http://localhost:9090/job/artifactory-8.0-release/artifactory/staging?
it is working fine, but it is asking for authentication. When i do automate, i need to call this only using token not with user credentials.
please help.
There are several ways to use tokens for authentication.
Basic Authentication
curl -u<USERNAME>:<TOKEN> http://ARTIFACTORY_URL/api/system/ping
Authorization Headers
curl -H"Authorization: Bearer <TOKEN>" http://ARTIFACTORY_URL/api/system/ping
Source: JFrog Artifactory documenation page 'Access Tokens'

Jenkins doesn't allow my build token

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.

Resources