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

Commit d1bf5e4

Browse files
author
Steve Peak
authored
Merge pull request #56 from rochdev/blue-ocean
Add support for Jenkins Blue Ocean
2 parents b365cd8 + 0a3cea3 commit d1bf5e4

File tree

9 files changed

+60
-14
lines changed

9 files changed

+60
-14
lines changed

lib/git.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var execSync = require("child_process").execSync;
2+
3+
module.exports = {
4+
5+
branch: function(){
6+
return execSync("git rev-parse --abbrev-ref HEAD || hg branch").toString().trim();
7+
},
8+
9+
head: function(){
10+
return execSync("git log -1 --pretty=%H || hg id -i --debug | tr -d '+'").toString().trim();
11+
}
12+
13+
};

lib/services/drone.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var execSync = require('child_process').execSync;
1+
var git = require('../git');
22

33
module.exports = {
44

@@ -11,7 +11,7 @@ module.exports = {
1111
return {
1212
service : 'drone.io',
1313
build : process.env.DRONE_BUILD_NUMBER,
14-
commit : execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim(),
14+
commit : git.head(),
1515
build_url : process.env.DRONE_BUILD_URL,
1616
branch : process.env.DRONE_BRANCH,
1717
root : process.env.DRONE_BUILD_DIR

lib/services/jenkins.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var git = require('../git');
2+
13
module.exports = {
24

35
detect : function(){
@@ -8,12 +10,12 @@ module.exports = {
810
console.log(' Jenkins CI Detected');
911
return {
1012
service : 'jenkins',
11-
commit : process.env.ghprbActualCommit || process.env.GIT_COMMIT,
12-
branch : process.env.ghprbSourceBranch || process.env.GIT_BRANCH,
13+
commit : process.env.ghprbActualCommit || process.env.GIT_COMMIT || git.head(),
14+
branch : process.env.ghprbSourceBranch || process.env.GIT_BRANCH || process.env.BRANCH_NAME,
1315
build : process.env.BUILD_NUMBER,
1416
build_url : process.env.BUILD_URL,
1517
root : process.env.WORKSPACE,
16-
pr : process.env.ghprbPullId
18+
pr : process.env.ghprbPullId || process.env.CHANGE_ID
1719
};
1820
}
1921

lib/services/localGit.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
var execSync = require('child_process').execSync;
1+
var git = require('../git')
22

33
module.exports = {
44

55
configuration : function(){
66
console.log(' No CI Detected. Using git/mercurial');
7-
var branch = execSync("git rev-parse --abbrev-ref HEAD || hg branch").toString().trim();
7+
var branch = git.branch();
88
if (branch === 'HEAD') {
99
branch = 'master';
1010
}
11-
var head = execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim();
11+
var head = git.head();
1212
return {
1313
commit : head,
1414
branch : branch

test/detect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var detect = require("../lib/detect");
2-
var execSync = require('child_process').execSync;
2+
var git = require("../lib/git");
33

44
describe("Codecov", function(){
55

@@ -13,7 +13,7 @@ describe("Codecov", function(){
1313

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

1919
});

test/git.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var git = require("../lib/git");
2+
var execSync = require("child_process").execSync;
3+
4+
describe("Git", function(){
5+
6+
it("can get the branch", function(){
7+
expect(git.branch()).to.eql(execSync("git rev-parse --abbrev-ref HEAD || hg branch").toString().trim());
8+
});
9+
10+
it("can get the head", function(){
11+
expect(git.head()).to.eql(execSync("git log -1 --pretty=%H || hg id -i --debug | tr -d '+'").toString().trim());
12+
});
13+
14+
});

test/services/drone.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var drone = require("../../lib/services/drone");
2-
var execSync = require('child_process').execSync;
2+
var git = require("../../lib/git");
33

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

@@ -15,7 +15,7 @@ describe("Drone.io CI Provider", function(){
1515
process.env.DRONE_BUILD_DIR = '/';
1616
expect(drone.configuration()).to.eql({
1717
service : 'drone.io',
18-
commit : execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim(),
18+
commit : git.head(),
1919
build : '1234',
2020
root : '/',
2121
branch : 'master',

test/services/jenkins.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var jenkins = require("../../lib/services/jenkins");
2+
var git = require("../../lib/git");
23

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

@@ -24,6 +25,24 @@ describe("Jenkins CI Provider", function(){
2425
});
2526
});
2627

28+
it ("can get service env info when using Blue Ocean", function(){
29+
delete process.env.GIT_COMMIT;
30+
delete process.env.GIT_BRANCH;
31+
process.env.BUILD_NUMBER = '1234';
32+
process.env.BUILD_URL = 'http://asdf/';
33+
process.env.BRANCH_NAME = 'master';
34+
process.env.WORKSPACE = '/';
35+
expect(jenkins.configuration()).to.eql({
36+
service : 'jenkins',
37+
build_url : 'http://asdf/',
38+
build : '1234',
39+
root : '/',
40+
commit : git.head(),
41+
pr : undefined,
42+
branch : 'master'
43+
});
44+
})
45+
2746
it ("github pull request env variables win out over jenkins variables", function(){
2847
process.env.BUILD_NUMBER = '1234';
2948
process.env.BUILD_URL = 'http://asdf/';

test/upload.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var fs = require('fs');
22
var codecov = require('../lib/codecov');
33
var offlineErrors = require('../lib/offline');
4-
var execSync = require('child_process').execSync;
5-
64

75
describe("Codecov", function(){
86
it("can get upload to v2", function(done){

0 commit comments

Comments
 (0)