0

I wanted to know if there is any good documentation available for the below scenario

I have a jenkins master running on my laptop This jenkins master have several jobs which executes locally

I now want to call these jobs from Azure Dev Ops. Meaning a Devops job from Azure cloud should trigger a build on my local Jenkins setup

I saw several videos but I am finding it difficult to get around it.

Is there any easier way by just making use of a plugin to connect and executing the job?

I did saw some Udemy videos but then those involve a lot of setting to be done and does expose your system to outside vulnarabilities as firewalls and router settings are played on with.

Any help would be appreciated. Thanks!

Pankaj Harde
  • 55
  • 1
  • 11

1 Answers1

1

You can enable Trigger builds remotely for your jenkins jobs, and then use a script task in the azure devops pipeline to trigger your jenkins pipeline. See below steps:

1, Firstly you need to create a self-hosted agent on your local jenkins server machine. Since the jenkins server is running locally, you need a local agent to communicate with your local jenkins server. Follow the steps here to create your local hosted agent.

2, Enable Trigger builds remotely on Jenkins

Go the the Build Triggers Tab of your jenkins pipeline configure page--> Then check Trigger builds remotely--> Specify a Token (will be used in the URL) enter image description here

3, Define a secret variable to host your jenkins password in azure devops pipeline:

enter image description here

4, Add a bash task in your azure devops pipeline to run the below curl command:

#token must be the same with the token you entered in above step
curl -u $(username):$(password) http://localhost:8080/job/myproject/build?token=anytoken 

enter image description here

See this thread trigger jenkins job via curl command remotely for more information.

5, Targeting your self-hosted agent pool to run your azure devops pipeline on self-hosted agent.

enter image description here

Then your local jenkin jobs will be triggered by the azure devops jobs.

Update:

You can also use Jenkins queue job task to queue a jenkin job in azure devops pipeline. See below steps:

1, Create a API Token in your Jenkin server.

Go your jenkin account configure page. To create a API token.

enter image description here

2, Add Jenkins queue job task in azure devops pipeline.

enter image description here

3, Click the Manage link to create a jenkins service connection--> In the newly opened page-->Create Service connection-->Select Jenkins--> Next

Enter the required information as below screenshot. Note: username is your user account for jenkin server, the Password is the API Token You generated in above step.

enter image description here

4, Configure your Jenkin queue job task as below

enter image description here

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/219413/discussion-on-answer-by-levi-lu-msft-integrating-local-jenkins-setup-with-azure). – Samuel Liew Aug 07 '20 at 13:57
  • My Jenkins instance returns 302 on every Jenkins Queue Job Task call. Because of this, Azure DevOps marks the build as failed, even though it succeeds in Jenkins. It is likely a bug in Jenkins: https://stackoverflow.com/a/63408621/2404492 – Alexandr Zarubkin Oct 27 '21 at 20:54