简体   繁体   中英

Jenkinsfile Pipeline (Declarative): Trigger my pipeline on push commits to a Github repo

I have a question about triggering my pipeline.

Github Repo A:

  • contains my Jenkinsfile
  • checks out Repo B
  • executes script in Repo B

Github Repo B:

  • containers scripts
  • Will be executed as part of my pipeline

So I want this pipeline to be triggered every time a commit is pushed into Repo B, what is the best way to do that? Is using Github webhooks the best way to do this?

I had a similar issue. My JenkinsFile was not in the same SCM I want to watch and trigger by BitBucket push.

SCM CodeBase   JenkinsFile.groovy
SCM SourceCpp  <project>

I tried to create declarative pipeline with JenkinsFile.groovy to be triggered for push into SourceCpp.

So far I have tried:

Poll SCM - does not work, I cannot specify what SCM to poll. Trigger builds remotely - obvious security risk, cannot have API key in cleartext. GitHub - not applicable for my BitBucket. Bitbucket webhook trigger - cannot override SCM to SourceCpp
Build when a change is pushed to BitBucket - promising, but does not work/trigger despite I have overrided URL.

But there is a solution:

  1. Create new FreeStyle job Dull_project with SCM SourceCpp.
  2. Setup simple Bitbucket webhook trigger (or any other trigger you like) for its SCM changes.
  3. In JenkinsFile job select trigger Build after other projects are built

or as a declarative syntax:

*triggers {
    // this is a hack to make dependency on SourceCpp.git work
    upstream 'Dull_project'
}*

Problem solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM