<p>First, you have to create a new job in Jenkins ( Github organization ) and configure it to scan all repos and all branches, you can do it by following this <a href="https://support.cloudbees.com/hc/en-us/articles/115003015711-GitHub-Webhook-Organization-Folder" rel="nofollow noreferrer">URL</a> 
second, press scan organization from Jenkins, now you will see all repos and all braches which contain Jenkinsfile which contains all your stages and all pipeline stages, check also this <a href="https://github.com/gitbucket/gitbucket/wiki/Setup-Jenkins-Multibranch-Pipeline-and-Organization" rel="nofollow noreferrer">URL</a></p>

CC BY-SA 4.0
2018-10-26T11:07:43.167Z
2018-10-26T11:07:43.167Z
Ahmed Badawy
<p>According to the <a href="https://go.cloudbees.com/docs/cloudbees-documentation/cje-user-guide/index.html#github-branch-source" rel="nofollow noreferrer">official GitHub Branch Source Plugin documentation</a>, the plugin can automatically configure webhooks for you if you have your GitHub API token configured in Jenkins global settings:</p>

<blockquote>
  <p>You can change the build configuration to perform the folder
  computation at different times. The default setting will scan your
  GitHub repository for changes if it has not received any change
  notifications from GitHub within the past day. This scan will catch
  the repositories you’ve added or removed from the managed GitHub
  repository. You can always force the Folder Computation to run from
  the GitHub Organization page.</p>
  
  <p>While the build triggers are often enough, you can set up webhooks to
  automatically trigger builds when changes are pushed to your GitHub
  repositories. To do this you must have a GitHub login with a token.</p>
  
  <ol>
  <li><p>Go to the main configuration settings page, Manage Jenkins > Configure System</p></li>
  <li><p>In the GitHub Plugin Configuration section, add a server with your credentials</p></li>
  <li><p>If you need a token, generate one with the Additional Actions > Convert login to password and token</p></li>
  </ol>
  
  <p>You can also configure this manually through GitHub itself by
  registering the URL provided in the help section of the server config.</p>
</blockquote>

CC BY-SA 4.0
2018-05-03T17:02:15.760Z
2018-05-03T17:02:15.760Z
jayhendren
<p>I'm setting up a CI scheme for a few projects, on Jenkins, using the multibranch plugin.
Everything is working pretty nicely, but the obsessive in me always wants a bit more.</p>

<p>Current situation:<br>
The multibranch thingy is working: picks up and builds new branches and PRs. It does so by polling: Every N minutes it polls Github for new branches and branch updates.</p>

<p>I want:<br>
I would very much like to build new pushes on Github Webhook push events and avoid polling. When not dealing with multibranch, it was as simple as checking the <code>GitHub hook trigger for GITScm polling</code> box.
In this context, I would have to add a new trigger to the Jenkinsfile. I assume something like:</p>

<pre><code>triggers {
    githubWebhook()
}
</code></pre>

<p>Currently, my Jenkinsfile is something like this:</p>

<pre><code>pipeline {
    agent {
        docker {
            image '${REDACTED}/builder:sbt-0.13-jdk-oracle-8'
            args '-v sbt-cache:/root/.sbt/ -v ivy-cache:/root/.ivy2/'
            customWorkspace '/src/'
        }
    }
    options {
        buildDiscarder(logRotator(numToKeepStr: '10'))
        timestamps()
        timeout(time: 1, unit: 'HOURS')
    }
    stages {
        stage('Testing') {
            steps {
                sh "sbt clean coverage test coverageReport coverageAggregate sonar"
            }
        }

        stage('Push snapshot'){
            when {
                not {
                    branch 'master'
                }
            }
            steps {
                echo "[DRYRUN] sbt publishSnapshot"
            }
        }

        stage('Push release') {
            when {
                branch 'master'
            }
            steps {
                echo "[DRYRUN] sbt publish"
            }
        }
    }
    post {
        changed {
            echo "[DRYRUN] changed build"
        }
    }
}
</code></pre>

<p>Has anyone dealt with something like this? Any other approach?</p>

CC BY-SA 4.0
2018-05-03T01:26:51.083Z
Maybe relevant: https://stackoverflow.com/questions/43314483/how-to-trigger-multibranch-pipeline-build-with-github-webhook
Dan Cornilescu
<jenkins><continuous-integration><github>
Enabling Github webhooks for multibranch jobs?
Nico Villanueva
# Enabling Github webhooks for multibranch jobs?

(Asked by: username_0 on 2018-05-02)

I'm setting up a CI scheme for a few projects, on Jenkins, using the multibranch plugin.
Everything is working pretty nicely, but the obsessive in me always wants a bit more.
Current situation:
The multibranch thingy is working: picks up and builds new branches and PRs. It does so by polling: Every N minutes it polls Github for new branches and branch updates.
I want:
I would very much like to build new pushes on Github Webhook push events and avoid polling. When not dealing with multibranch, it was as simple as checking the GitHub hook trigger for GITScm polling box.
In this context, I would have to add a new trigger to the Jenkinsfile. I assume something like:
triggers {
    githubWebhook()
}

Currently, my Jenkinsfile is something like this:
pipeline {
    agent {
        docker {
            image '${REDACTED}/builder:sbt-0.13-jdk-oracle-8'
            args '-v sbt-cache:/root/.sbt/ -v ivy-cache:/root/.ivy2/'
            customWorkspace '/src/'
        }
    }
    options {
        buildDiscarder(logRotator(numToKeepStr: '10'))
        timestamps()
        timeout(time: 1, unit: 'HOURS')
    }
    stages {
        stage('Testing') {
            steps {
                sh "sbt clean coverage test coverageReport coverageAggregate sonar"
            }
        }

        stage('Push snapshot'){
            when {
                not {
                    branch 'master'
                }
            }
            steps {
                echo "[DRYRUN] sbt publishSnapshot"
            }
        }

        stage('Push release') {
            when {
                branch 'master'
            }
            steps {
                echo "[DRYRUN] sbt publish"
            }
        }
    }
    post {
        changed {
            echo "[DRYRUN] changed build"
        }
    }
}

Has anyone dealt with something like this? Any other approach?

**Tags:** jenkins, continuous-integration, github

> **Comments:**
> **username_1**: Maybe relevant: https://stackoverflow.com/questions/43314483/how-to-trigger-multibranch-pipeline-build-with-github-webhook  

---

## 2 answers

### Answer by username_2 on 2018-10-26. Score: 1

First, you have to create a new job in Jenkins ( Github organization ) and configure it to scan all repos and all branches, you can do it by following this [URL](https://support.cloudbees.com/hc/en-us/articles/115003015711-GitHub-Webhook-Organization-Folder)
second, press scan organization from Jenkins, now you will see all repos and all braches which contain Jenkinsfile which contains all your stages and all pipeline stages, check also this [URL](https://github.com/gitbucket/gitbucket/wiki/Setup-Jenkins-Multibranch-Pipeline-and-Organization)


---

### Answer by username_3 on 2018-05-03. Score: 1

According to the [official GitHub Branch Source Plugin documentation](https://go.cloudbees.com/docs/cloudbees-documentation/cje-user-guide/index.html#github-branch-source), the plugin can automatically configure webhooks for you if you have your GitHub API token configured in Jenkins global settings:

> You can change the build configuration to perform the folder
> computation at different times. The default setting will scan your
> GitHub repository for changes if it has not received any change
> notifications from GitHub within the past day. This scan will catch
> the repositories you’ve added or removed from the managed GitHub
> repository. You can always force the Folder Computation to run from
> the GitHub Organization page.
>
> While the build triggers are often enough, you can set up webhooks to
> automatically trigger builds when changes are pushed to your GitHub
> repositories. To do this you must have a GitHub login with a token.
>
> 1. Go to the main configuration settings page, Manage Jenkins > Configure System
> 2. In the GitHub Plugin Configuration section, add a server with your credentials
> 3. If you need a token, generate one with the Additional Actions > Convert login to password and token
>
> You can also configure this manually through GitHub itself by
> registering the URL provided in the help section of the server config.


---

