Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Setup Jenkins Multibranch Pipeline and Organization

Jerry edited this pageMay 18, 2020 ·9 revisions

This page shows how to setup Jenkins Multibranch Pipeline jobs and Organization folders.

Prerequisite

  • 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 ashttp://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.

Creating a Multibranch Pipeline job

Configure Jenkins:

  1. OpenManage Jenkins -Configure System.
  2. Add a server inGitHub Enterprise Servers section. API endpoint should be likehttp://gitbucket.example.com/api/v3.

Add a job on Jenkins:

  1. OpenNew Item.
  2. Enter job name and mark as aMultibranch Pipeline. Then, clickOK.
  3. Add a GitHub source inBranch Sources section.
    • API endpoint: selectGitBucket (http://gitbucket.example.com/api/v3).
    • Credentials: required if anonymous access is denied on GitBucket.
    • Owner: user or group
    • Repository: select your repository
  4. ClickSave.

Configure a webhook on GitBucket:

  1. Open your repository -Settings -Service Hooks.
  2. ClickAdd webhook button.
  3. Fill followings and save.
    • Payload URL:http://jenkins.example.com/github-webhook/
    • Which events would you like to trigger this webhook?: Push, Pull Request

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.

Creating an Organization folder

Add a job on Jenkins:

  1. OpenNew Item.
  2. Enter job name and mark as aGitHub Organization. Then, clickOK.
  3. Add a GitHub source inBranch Sources section.
    • API endpoint: selectGitBucket (http://gitbucket.example.com/api/v3).
    • Credentials: required if anonymous access is denied on GitBucket.
    • Owner: group
  4. ClickSave.

Configure a webhook on GitBucket:

  1. Open your group -Edit group -Service Hooks.
  2. ClickAdd webhook button.
  3. Fill followings and save.
    • Payload URL:http://jenkins.example.com/github-webhook/
    • Which events would you like to trigger this webhook?: Push, Pull Request

Then, your group and repositories should be shown in Jenkins.

For better security

Configure GitBucket:

  1. OpenSystem settings and setAnonymous access toDeny.
  2. Createjenkins user and add it to your group.

Configure Jenkins:

  1. OpenCredentials -Add Credentials.
  2. Fill followings and save.
    • Username:jenkins
    • Password: password ofjenkins
    • Description:GitBucket access credential

Then, fix jobs to use credentials.

Pitfalls

Jenkins tries to clone from the wrong URL and uses an old Git client

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 unexpectedly

Then, 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.

See also

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp