Is it possible to trigger a GitHub webhooks build - from another repo?

43 views
Skip to first unread message

Danijel DOMAZET

unread,
Mar 19, 2021, 9:54:55 AM3/19/21
to Jenkins Users
Hi, 
My repo_main "depends" on several other repos. It internally uses a script to git clone repo_a, repo_b and repo_c into subdirs. 

This poses a problem when using webhooks to trigger Jenkins builds from GitHub. 

The question is: is there a way to trigger a build in repo_main when there has been a push in either repo_a, repo_b, or repo_c

Any help most appreciated... 
Thanks, Danijel.

- Confidential -

gma...@gmail.com

unread,
Mar 19, 2021, 10:05:15 AM3/19/21
to jenkins...@googlegroups.com

Hi,

You can do it from Jenkins itself.

 

For example, in our case we want the exact opposite, so we have in our pipeline:

 

stage('Setup') {
    when {
        beforeAgent
true
        anyOf {
            triggeredBy
'UpstreamCause'
            triggeredBy 'UserIdCause'
        }
    }
    steps {

 

The above tells Jenkins to run the steps only if the build has been triggered by an upstream job or by a user.

 

To get what you want, you need a similar thing in repo_a, repo_b and repo_c that triggers the repo_main when webhook arrives:

 

stage('Setup') {
    when {
        beforeAgent
true
        anyOf {
            triggeredBy
'SomethingGitHubTrigger' // look on internet for the exact name, I don’t know
            triggeredBy 'UserIdCause'
        }
    }
    steps {
build([
   
job:
       
"Your repo_main job",
   
wait: false,
   
propagate: false
])

 

And then everytime someone pushed on repo_a/b/c then the repo_main build is triggered on cascade.

 

I hope that helps.

Cheers,

Gianluca.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ac0642e3-13e3-4945-86b9-6fa93bbc0e9cn%40googlegroups.com.

Danijel DOMAZET

unread,
Mar 19, 2021, 11:46:37 AM3/19/21
to Jenkins Users
Thanks, that really helped. 
I managed to easily trigger another job from the main one using build([job...
 
But, somehow I cannot get GitHub to trigger the repo_main... the webhook is sent, but not received by the repo_main.
I tried triggeredBy 'GitHubPushTrigger' but still nothing. 

What am I doing wrong? 
Thanks. 



Reply all
Reply to author
Forward
0 new messages