- Notifications
You must be signed in to change notification settings - Fork1.3k
Setup Jenkins Multibranch Pipeline and Organization
This page shows how to setup Jenkins Multibranch Pipeline jobs and Organization folders.
- GitBucket is running.
- Jenkins is running.
- Jenkins Multibranch Pipeline is installed.
- Jenkins Github Branch Source Plugin is installed.
- Jenkins can access to GitBucket without port number and context path, such as
http://gitbucket.example.com.
To clarify the above, the requirements on the "Base URL", arevery strict.
- "Base URL" is in root -> System Administration -> System Settings
- A value must be provided, otherwise it will default to localhost in URLs, which won't work for webhooks
- YouMUST start Gitbucket with a custom "port" of 80 as documentedhere.Issue
- JenkinsMUST reach Gitbucket on port 80, it cannot go through a port mapping.
- YouMUST NOT start Gitbucket with a custom "prefix" as documentedhere.Issue
These requirements mostly stem from certain assumptions and nuances of the Github plugin on Jenkins. For example, the plugin erroneously strips off custom ports from URL's when trying to reach Gitbucket. Also, the plugin performs URL matching on webhooks, and the webhook URL has to be an exact match of the repo URL the plugin discovered previously. There are other contributing behaviors as well. If these limitations render your use-case impossible (such as you require custom port mappings), please open a ticket.
Configure Jenkins:
- OpenManage Jenkins -Configure System.
- Add a server inGitHub Enterprise Servers section. API endpoint should be like
http://gitbucket.example.com/api/v3.
Add a job on Jenkins:
- OpenNew Item.
- Enter job name and mark as aMultibranch Pipeline. Then, clickOK.
- Add a GitHub source inBranch Sources section.
- API endpoint: select
GitBucket (http://gitbucket.example.com/api/v3). - Credentials: required if anonymous access is denied on GitBucket.
- Owner: user or group
- Repository: select your repository
- API endpoint: select
- ClickSave.
Configure a webhook on GitBucket:
- Open your repository -Settings -Service Hooks.
- ClickAdd webhook button.
- Fill followings and save.
- Payload URL:
http://jenkins.example.com/github-webhook/ - Which events would you like to trigger this webhook?: Push, Pull Request
- Payload URL:
Create aJenkinsfile on your repository:
pipeline { agent any stages { stage('build') { steps { sh'echo Building ${BRANCH_NAME}...' } } }}A new build should be started immediately on Jenkins.
Add a job on Jenkins:
- OpenNew Item.
- Enter job name and mark as aGitHub Organization. Then, clickOK.
- Add a GitHub source inBranch Sources section.
- API endpoint: select
GitBucket (http://gitbucket.example.com/api/v3). - Credentials: required if anonymous access is denied on GitBucket.
- Owner: group
- API endpoint: select
- ClickSave.
Configure a webhook on GitBucket:
- Open your group -Edit group -Service Hooks.
- ClickAdd webhook button.
- Fill followings and save.
- Payload URL:
http://jenkins.example.com/github-webhook/ - Which events would you like to trigger this webhook?: Push, Pull Request
- Payload URL:
Then, your group and repositories should be shown in Jenkins.
Configure GitBucket:
- OpenSystem settings and setAnonymous access toDeny.
- Create
jenkinsuser and add it to your group.
Configure Jenkins:
- OpenCredentials -Add Credentials.
- Fill followings and save.
- Username:
jenkins - Password: password of
jenkins - Description:
GitBucket access credential
- Username:
Then, fix jobs to use credentials.
If your build fails with the following message:
hudson.plugins.git.GitException: Command "git fetch --no-tags --progress http://servername/Owner/Repo.git +refs/heads/master:refs/remotes/origin/master" returned status code 128:stdout:stderr: error: RPC failed; result=22, HTTP code = 404fatal: The remote end hung up unexpectedlyThen, this is caused by Jenkins trying to fetch from the Git repository under the URLhttp://servername/Owner/Repo.git instead ofhttp://servername/git/Owner/Repo.git. GitBucket provides a redirect from the former to the latter URL, but this is not supported by older versions of Git.
A solution can be to install a newer Git client on the machine doing the checkout.