-1

I have a Jenkins job running on my localhost:8080. I want to trigger this job automatically whenever there is a commit on Azure repos (Azure DevOps).

Any advise on how I can achieve this? Thanks

SD4
  • 439
  • 10
  • 27
  • What research have you done? What have you tried? – Daniel Mann Mar 06 '21 at 17:06
  • @DanielMann I came across the service hooks on Azure DevOps. When I proceed with it, I'm required to enter my jenkins base url. However, I can't use localhost in there. So I was wondering if there's an alternative to this method or if there's a workaround regarding the base url. – SD4 Mar 07 '21 at 08:16
  • 'localhost' means 'yourself' - 127.0.0.1; An ADO build agent will view 'localhost' as itself, ie. the agent that ADO is running on; You need to find the actual name or IP address of the machine where the jenkins job is running. – Ed Randall Mar 07 '21 at 16:13

1 Answers1

1

Since Jenkins job running on your localhost:8080. You need to create your self-hosted agents on the local machine which your jenkin server can communicate to. Then you need to create a azure pipeline to be triggered on Azure repos commit and run this azure pipeline on your self-hosted agent. You can check out below workarounds:

  • 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)

  • Define a secret variable to host your jenkins password(eg. password) in azure devops pipeline:

  • 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 
    
  • Targeting your self-hosted agent pool to run your azure devops pipeline on self-hosted agent.

There is another workaround using Jenkins queue job task.

  • Create a API Token in your Jenkin server.

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

  • Add Jenkins queue job task in azure devops pipeline

  • 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. Note: url is your local jenkin server. username is your user account for jenkin server, the Password is the API Token You generated in above step.

Another workaround is to configure the Poll SCM build triggers on your jenkins job. So that the jenkin server will periodically poll the source code and queue the job if there is new commit.

See this thread for more information.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43