AVarf
AVarf

Reputation: 5149

How to trigger a Jenkins pipeline from multiple repositories

I am relatively new to Jenkins and I am working on a large project that pulls from multiple repos to build. I wrote a declarative pipeline with shell commands that pull from the required repos and build the project and everything is working but I want to connect this pipeline to all these repos so every time there is a new commit or a pull request, a Jenkins job is triggered and then I return the build result to tag the git commit. I know how to do this for one repo, but I don't know how to do it for multiple repos.

Upvotes: 5

Views: 5845

Answers (2)

LeonG
LeonG

Reputation: 440

If you have multiple repositories which should trigger Jenkins builds, the respective repositories need to have Jenkinsfiles in place.

The key is that every repository should call a JenkinsSharedLibrary, which gives you the ability to maintain your Jenkins builds in one central source, instead of having multiple "hardcoded" Jenkinsfiles per repository.

This article describes the use case of a shared library and how to use Jenkins across multiple git repos: https://bjurr.se/managing-1000-repos-in-jenkins-with-a-breeze/

Upvotes: 4

AVarf
AVarf

Reputation: 5149

Because of our network infrastructure I couldn't use webhook to trigger jenkins but the solution that I am using now is I created a runner for each repo and I wrote a curl command to trigger jenkins with so each time that there is a new commit to each of those repos the runner starts a new job, executes that curl command and triggers my jenkins job.

This is the curl command that I am using in case someone needed it:

curl -i -X POST --user [JENKINS_USERNAME]:[JENKINS_PASSWORD] 'http://[JENKINS_IP]:[JENKINS_PORT]/job/[JENKINS_JOB_NAME]/build?token=[TOKEN_GENERATED_INSIDE_JENKINS]&cause=[ADDITIONAL_INFORMATION_THAT_YOU_WANT_TO_PRINT]'

Upvotes: 5

Related Questions