Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Add support for Jenkins Blue Ocean
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev committed Mar 28, 2017
1 parent 3c8fb1b commit 0530519
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 31 deletions.
13 changes: 13 additions & 0 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var execSync = require("child_process").execSync;

module.exports = {

branch: function(){
return execSync("git rev-parse --abbrev-ref HEAD || hg branch").toString().trim();
},

head: function(){
return execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim();
}

};
4 changes: 2 additions & 2 deletions lib/services/drone.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var execSync = require('child_process').execSync;
var git = require('../git');

module.exports = {

Expand All @@ -11,7 +11,7 @@ module.exports = {
return {
service : 'drone.io',
build : process.env.DRONE_BUILD_NUMBER,
commit : execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim(),
commit : git.head(),
build_url : process.env.DRONE_BUILD_URL,
branch : process.env.DRONE_BRANCH,
root : process.env.DRONE_BUILD_DIR
Expand Down
8 changes: 5 additions & 3 deletions lib/services/jenkins.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var git = require('../git');

module.exports = {

detect : function(){
Expand All @@ -8,12 +10,12 @@ module.exports = {
console.log(' Jenkins CI Detected');
return {
service : 'jenkins',
commit : process.env.ghprbActualCommit || process.env.GIT_COMMIT,
branch : process.env.ghprbSourceBranch || process.env.GIT_BRANCH,
commit : process.env.ghprbActualCommit || process.env.GIT_COMMIT || git.head(),
branch : process.env.ghprbSourceBranch || process.env.GIT_BRANCH || process.env.BRANCH_NAME,
build : process.env.BUILD_NUMBER,
build_url : process.env.BUILD_URL,
root : process.env.WORKSPACE,
pr : process.env.ghprbPullId
pr : process.env.ghprbPullId || process.env.CHANGE_ID
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/services/localGit.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var execSync = require('child_process').execSync;
var git = require('../git')

module.exports = {

configuration : function(){
console.log(' No CI Detected. Using git/mercurial');
var branch = execSync("git rev-parse --abbrev-ref HEAD || hg branch").toString().trim();
var branch = git.branch();
if (branch === 'HEAD') {
branch = 'master';
}
var head = execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim();
var head = git.head();
return {
commit : head,
branch : branch
Expand Down
10 changes: 2 additions & 8 deletions test/detect.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@

var detect = require("../lib/detect");
var execSync = require('child_process').execSync;
if (!execSync) {
var exec = require('execSync').exec;
var execSync = function(cmd){
return exec(cmd).stdout;
};
}
var git = require("../lib/git");

describe("Codecov", function(){

Expand All @@ -20,7 +14,7 @@ describe("Codecov", function(){

it("can select local git service if no service is found", function(){
expect(detect().commit).to.match(/^\w{40}$/);
expect(detect().commit).to.eql(execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim());
expect(detect().commit).to.eql(git.head());
});

});
14 changes: 14 additions & 0 deletions test/git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var git = require("../lib/git");
var execSync = require("child_process").execSync;

describe("Git", function(){

it("can get the branch", function(){
expect(git.branch()).to.eql(execSync("git rev-parse --abbrev-ref HEAD || hg branch").toString().trim());
});

it("can get the head", function(){
expect(git.head()).to.eql(execSync("git log -1 --pretty=%H || hg id -i --debug | tr -d '+'").toString().trim());
});

});
10 changes: 2 additions & 8 deletions test/services/drone.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
var drone = require("../../lib/services/drone");
var execSync = require('child_process').execSync;
if (!execSync) {
var exec = require('execSync').exec;
var execSync = function(cmd){
return exec(cmd).stdout;
};
}
var git = require("../../lib/git");

describe("Drone.io CI Provider", function(){

Expand All @@ -21,7 +15,7 @@ describe("Drone.io CI Provider", function(){
process.env.DRONE_BUILD_DIR = '/';
expect(drone.configuration()).to.eql({
service : 'drone.io',
commit : execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim(),
commit : git.head(),
build : '1234',
root : '/',
branch : 'master',
Expand Down
19 changes: 19 additions & 0 deletions test/services/jenkins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var jenkins = require("../../lib/services/jenkins");
var git = require("../../lib/git");

describe("Jenkins CI Provider", function(){

Expand All @@ -24,6 +25,24 @@ describe("Jenkins CI Provider", function(){
});
});

it ("can get service env info when using Blue Ocean", function(){
delete process.env.GIT_COMMIT;
delete process.env.GIT_BRANCH;
process.env.BUILD_NUMBER = '1234';
process.env.BUILD_URL = 'http://asdf/';
process.env.BRANCH_NAME = 'master';
process.env.WORKSPACE = '/';
expect(jenkins.configuration()).to.eql({
service : 'jenkins',
build_url : 'http://asdf/',
build : '1234',
root : '/',
commit : git.head(),
pr : undefined,
branch : 'master'
});
})

it ("github pull request env variables win out over jenkins variables", function(){
process.env.BUILD_NUMBER = '1234';
process.env.BUILD_URL = 'http://asdf/';
Expand Down
7 changes: 0 additions & 7 deletions test/upload.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
var fs = require('fs');
var codecov = require('../lib/codecov');
var offlineErrors = require('../lib/offline');
var execSync = require('child_process').execSync;
if (!execSync) {
var exec = require('execSync').exec;
var execSync = function(cmd){
return exec(cmd).stdout;
};
}


describe("Codecov", function(){
Expand Down

0 comments on commit 0530519

Please sign in to comment.