This page provides information on how to setup Jenkins GitHub Branch Source plugin with GitBucket to use the GitHub Organization template job.
tested with https://github.com/gitbucket/gitbucket/releases/tag/4.15.0
http://jenkins:9090/
http://gitbucket:8080/I will create a NodeJS project, to run simple build and tests
http://gitbucket:8080/wey-yu/hello (my group is named "wey-yu")hello repository on GitBucket (in the wey-yu group) as http://gitbucket:8080/wey-yu/hello (and initialize this repository with a README file)git clone http://gitbucket:8080/git/wey-yu/hello.git). ├── README.md ├── index.js ├── Jenkinsfile ├── package.json ├── .gitignore └── tests └── test.js
package.json{
"name": "hello",
"description": "hello",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/mocha tests/**",
"start": "node index.js"
},
"devDependencies": {
"chai": "^4.1.1",
"mocha": "^3.5.0"
}
}
test.js'use strict';
const expect = require('chai').expect;
describe('# 42 is 42', () => {
it('should equal 42', () => {
expect(42).to.equal(42);
});
});
.gitignorenode_modules/*
Jenkinsfilethe
Jenkinsfiletells to Jenkins what to do at each push of commit
node {
stage('Checkout') {
git url: env.GITBUCKET_URL + "/wey-yu/hello.git", branch: env.BRANCH_NAME
}
stage('Build') {
def nodeHome = tool name: 'nodejs', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
env.PATH = "${nodeHome}/bin:${env.PATH}"
sh "npm install"
sh "npm test"
}
}
you can write what you want inside
index.js
git add . git commit -m "🚀 first version of hello" git push origin master
indythebot (in fact whatever you want)
indythebot as a collaborator of repository wey-yu/hellohttp://jenkins:9090/github-webhook/ (⚠️ don't forget the / at the end of the url)
application/json for Content typeindythebot on http://gitbucket:8080/indythebot/_applicationhttp://jenkins:9090/configureEnvironment variablesGITBUCKET_URL with this value: http://gitbucket:8080/git (⚠️ don't forget the /git at the end of the url), this variable is used by the Jenkins filehttp://gitbucket:8080/api/v3gitbuckethttp://jenkins:9090/configureToolsnodejs (⚠️ this value is very important, it's used in the Jenkinsfile)Install automatically is checkedhttp://jenkins:9090/view/all/newJob
wey-yu group (aka orgnization)API endpoint with the gitbucket endpointindythebot as user and its password (so, the web token is probably useless) and then select this new credentialwey-yu)all branches strategyJenkinsfile value for the Script Path fieldPeriodically if not otherwise run checkbox, and set to 1 minute (because currently the web-hook seems not working correctly°hello repositoryhello repository (http://gitbucket:8080/wey-yu/hello/settings/options)Branches tab
master branchcontinuous-integration/jenkins/branchwip-display-hello) from master in GitBucketindex.js filehttp://jenkins:8080/job/wey-yu/job/hello/)wip-display-hello branchwip-display-hello) change the content of /tests/test.js to write a "bad" test:
'use strict';
const expect = require('chai').expect;
describe('# 42 is 42', () => {
it('should equal 42', () => {
expect(42).to.equal(42);
});
});That's all 😉