Curl request to validate the job list returned by Jenkins server

Lets say you have created a new Jenkins connector and while trying to use this connector suppose if you are unable to see any job thats is being listed in harness ui, so you can validate by making curl request via the delegate itself and compare if there is any mismatch:

curl https://$JENKINS_URL/crumbIssuer/api/json --user $USER:$PASSWORD

Replace JENKINS_URL and $USER:$PASSWORD

This will help us to get the crumb[CSRF protection uses a token (called crumb in Jenkins) that is created by Jenkins and sent to the user.]
You can find more details Jenkins Doc

You will get response something like below:

output:
4{
5  "_class":"hudson.security.csrf.DefaultCrumbIssuer",
6  "crumb":"$CRUMB,
7  "crumbRequestField":"Jenkins-Crumb"
8}

Now you can use the $CRUMB returned above and replace that in below curl and provide the JOB_NAME to list the job details:

curl --location --request GET 'https://$JENKINS_URL/job/$JOB_NAME/api/json' 
11--header 'Jenkins-Crumb: $CRUMB' 
12--user $USER:$PASSWORD
13--header 'Content-Type: application/x-www-form-urlencoded' 
14--data-urlencode 'verbosity=high'

1 Like