Unable to trigger jenkins remotely after integrated successfully with Azure AD

I have integrated Jenkins with Azure AD and it is working fine without any issue. Now i want to trigger jenkins job remotely. Previously i was using the jenkins username and password with curl it was working fine with the below command but now im using my Azure AD mail id and jenkins token it is not working. curl -X POST https://{name}.{org name}.com/job/[job name]/build --user jenkins_user:jenkins_user_token

Kindly help on how to do this with Azure AD Auth

Which command need to be used to trigger the jenkins job which is integrated with Azure AD

is that possible to create using powershell or batch or shell or python

Hello, @Haroon-Rash-DevOps and welcome to this community. :wave:

When Jenkins is integrated with Azure AD for authentication, I think you’ll need to use an access token or a personal access token (PAT) for triggering Jenkins jobs remotely instead of a username and password. :thinking:
PATs are typically used when you have integrated Jenkins with Azure AD and cannot access username and password authentication.

Here’s how you could trigger a Jenkins job using cURL with a PAT:

curl -X POST https://{name}.{org name}.com/job/[job name]/build \
     --user jenkins_user:{your_personal_access_token}

Replace {name}.{org name} with your Jenkins URL, [job name] with the name of the job you want to trigger, jenkins_user with your Jenkins username, and {your_personal_access_token} with your personal access token.

Hi, @poddingue ,
i already tried this approach, if i’m try it using my mail id and jenkins PAT getting below error

curl -X POST https://{name}.{org name}.com/job/[job name]/build
–user mailid:{jenkins_your_personal_access_token}

Error 401 Unauthorized

HTTP ERROR 401 Unauthorized

URI:/job/Test/build
STATUS:401
MESSAGE:Unauthorized
SERVLET:Stapler

Powered by Jetty:// 10.0.15

When you go to your user in Jenkins UI, what does it show as Jenkins User ID? Is it your mailid or some other id.
Have you granted the permissions to your mailid or some other id for accessing the job?

1 Like

image
I tried entering this user is and create token in jenkins and tried not working same authentication error

is thier any specific access needs to be provided for job trigger
normally this is the root admin user which got full access

When you click your name in the top bar of Jenkins, it should open a page that shows information like this:

Firstname Lastname

Azure Active Directory User

Unique Principal Name: firstname.lastname@example.com
Email: firstname.lastname@example.com
Object ID: d4a74085-6d97-47ea-9166-8e7ba2d1363a
Tenant ID: 69c34239-6bb5-4014-989c-45e443802619

:pencil2: Edit description

Jenkins User ID: d4a74085-6d97-47ea-9166-8e7ba2d1363a

The thing at the right side of “Jenkins User ID” is what you should use in the curl command. In my environment, it is the same as the “Object ID” shown above it. I have disabled Graph API integration in the Azure AD plugin though; I don’t know whether the format of the Jenkins User ID would change if I enabled that.

Hello, was wondering if you guys got it working without using an personal access token, and if so how was the actual procedure , we are also trying to generate an API Token via curl command with Azure AD auth enabled and the documentation seems to be lacking for that use-case.
If needed I can also start a new thread about this matter