-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anton Bayer
authored and
Anton Bayer
committed
May 25, 2016
1 parent
9162b6b
commit fe00fba
Showing
4 changed files
with
153 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,4 @@ | ||
"use strict"; | ||
var gulp = require('gulp'); | ||
var jenkins = require('jenkins')('http://user:[email protected]'); | ||
var fs = require('fs'); | ||
|
||
gulp.task('jenkinsUpload', function() { | ||
|
||
var projectName = process.env.npm_config_project_name; | ||
if (projectName === undefined) { | ||
projectName = ""; | ||
} | ||
var artifactGroup = process.env.npm_config_artifact_group; | ||
if (artifactGroup === undefined) { | ||
artifactGroup = ""; | ||
} | ||
var artifactId = process.env.npm_config_artifact_id; | ||
if (artifactId === undefined) { | ||
artifactId = ""; | ||
} | ||
var gitRepo = process.env.npm_config_git_repo; | ||
if (gitRepo === undefined) { | ||
gitRepo = ""; | ||
} | ||
var gitRepo = process.env.npm_config_git_repo; | ||
if (gitRepo === undefined) { | ||
gitRepo = ""; | ||
} | ||
var gitGroup = process.env.npm_config_git_group; | ||
if (gitGroup === undefined) { | ||
gitGroup = ""; | ||
} | ||
|
||
function getAllJobs() { | ||
|
||
fs.readdir("jobs-upload", function(err, files) { | ||
|
||
for (var i = 0;i<files.length;i++) { | ||
getFile(files[i]); | ||
} | ||
}); | ||
} | ||
|
||
function getFile(file){ | ||
|
||
fs.readFile("jobs-upload/" + file, 'utf8', function(err, data) { | ||
if (err){ | ||
return console.log(err); | ||
} | ||
checkJob(replacePlaceholder(file.replace(".xml", "")), replacePlaceholder(data)); | ||
}); | ||
} | ||
|
||
function checkJob(name, content) { | ||
|
||
jenkins.job.exists(name, function(err, exists) { | ||
if (err) throw err; | ||
|
||
if(exists) { | ||
updateJob(name, content); | ||
} | ||
else { | ||
createJob(name, content); | ||
} | ||
}); | ||
} | ||
|
||
function createJob(name, content) { | ||
|
||
jenkins.job.create(name, content, function(err) { | ||
if (err) throw err; | ||
console.log(name + " created."); | ||
}); | ||
} | ||
|
||
function updateJob(name, content) { | ||
|
||
jenkins.job.config(name, content, function(err) { | ||
if (err) throw err; | ||
console.log(name + " updated."); | ||
}); | ||
} | ||
|
||
function replacePlaceholder(str) { | ||
return str.replace(new RegExp('#GIT_GROUP#', 'g'), gitGroup) | ||
.replace(new RegExp('#GIT_REPO#', 'g'), gitRepo) | ||
.replace(new RegExp('#PROJECT_NAME#', 'g'), projectName) | ||
.replace(new RegExp('#ARTIFACT_GROUP#', 'g'), artifactGroup) | ||
.replace(new RegExp('#ARTIFACT_ID#', 'g'), artifactId); | ||
} | ||
|
||
getAllJobs(); | ||
}); | ||
|
||
gulp.task('jenkinsDownload', function() { | ||
|
||
function getAllJobs() { | ||
|
||
jenkins.job.list(function(err, data) { | ||
|
||
if (err){ | ||
return console.log(err); | ||
} | ||
|
||
if (data.length) { | ||
var callback = function(i) { | ||
i++; | ||
if (i < data.length) { | ||
getConfigXml(data[i].name, i, callback); | ||
} | ||
}; | ||
getConfigXml(data[0].name, 0, callback); | ||
} | ||
}); | ||
} | ||
|
||
function getConfigXml(name, index, callback){ | ||
|
||
jenkins.job.config(name, function(err, data) { | ||
if (err){ | ||
return console.log(name + " " + err); | ||
} | ||
|
||
saveJobConfigToFile(name, data, index, callback); | ||
}); | ||
} | ||
|
||
function saveJobConfigToFile(name, content, index, callback) { | ||
|
||
fs.writeFile("jobs-download/" + name + ".xml", content, function(err) { | ||
if(err) { | ||
return console.log(name + " " + err); | ||
} | ||
console.log(name + " saved"); | ||
|
||
callback(index); | ||
}); | ||
} | ||
|
||
getAllJobs(); | ||
}); | ||
require('./jenkins-download'); | ||
require('./jenkins-upload'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
|
||
var gulp = require('gulp'); | ||
var jenkinsProperties = require('./jenkins-properties'); | ||
var jenkins = require('jenkins')(jenkinsProperties.connection); | ||
var fs = require('fs'); | ||
|
||
gulp.task('jenkinsDownload', function() { | ||
|
||
function getAllJobs() { | ||
|
||
jenkins.job.list(function(err, data) { | ||
|
||
if (err){ | ||
return console.log(err); | ||
} | ||
|
||
if (data.length) { | ||
var callback = function(i) { | ||
i++; | ||
if (i < data.length) { | ||
getConfigXml(data[i].name, i, callback); | ||
} | ||
}; | ||
getConfigXml(data[0].name, 0, callback); | ||
} | ||
}); | ||
} | ||
|
||
function getConfigXml(name, index, callback){ | ||
|
||
jenkins.job.config(name, function(err, data) { | ||
if (err){ | ||
return console.log(name + " " + err); | ||
} | ||
|
||
saveJobConfigToFile(name, data, index, callback); | ||
}); | ||
} | ||
|
||
function saveJobConfigToFile(name, content, index, callback) { | ||
|
||
fs.writeFile("jobs-download/" + name + ".xml", content, function(err) { | ||
if(err) { | ||
return console.log(name + " " + err); | ||
} | ||
console.log(name + " saved"); | ||
|
||
callback(index); | ||
}); | ||
} | ||
|
||
getAllJobs(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
exports.connection = 'http://user:[email protected]'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use strict"; | ||
|
||
var gulp = require('gulp'); | ||
var jenkinsProperties = require('./jenkins-properties'); | ||
var jenkins = require('jenkins')(jenkinsProperties.connection); | ||
var fs = require('fs'); | ||
|
||
gulp.task('jenkinsUpload', function() { | ||
|
||
var projectName = process.env.npm_config_project_name; | ||
if (projectName === undefined) { | ||
projectName = ""; | ||
} | ||
var artifactGroup = process.env.npm_config_artifact_group; | ||
if (artifactGroup === undefined) { | ||
artifactGroup = ""; | ||
} | ||
var artifactId = process.env.npm_config_artifact_id; | ||
if (artifactId === undefined) { | ||
artifactId = ""; | ||
} | ||
var gitRepo = process.env.npm_config_git_repo; | ||
if (gitRepo === undefined) { | ||
gitRepo = ""; | ||
} | ||
var gitRepo = process.env.npm_config_git_repo; | ||
if (gitRepo === undefined) { | ||
gitRepo = ""; | ||
} | ||
var gitGroup = process.env.npm_config_git_group; | ||
if (gitGroup === undefined) { | ||
gitGroup = ""; | ||
} | ||
|
||
function getAllJobs() { | ||
|
||
fs.readdir("jobs-upload", function(err, files) { | ||
|
||
for (var i = 0;i<files.length;i++) { | ||
getFile(files[i]); | ||
} | ||
}); | ||
} | ||
|
||
function getFile(file){ | ||
|
||
fs.readFile("jobs-upload/" + file, 'utf8', function(err, data) { | ||
if (err){ | ||
return console.log(err); | ||
} | ||
checkJob(replacePlaceholder(file.replace(".xml", "")), replacePlaceholder(data)); | ||
}); | ||
} | ||
|
||
function checkJob(name, content) { | ||
|
||
jenkins.job.exists(name, function(err, exists) { | ||
if (err) throw err; | ||
|
||
if(exists) { | ||
updateJob(name, content); | ||
} | ||
else { | ||
createJob(name, content); | ||
} | ||
}); | ||
} | ||
|
||
function createJob(name, content) { | ||
|
||
jenkins.job.create(name, content, function(err) { | ||
if (err) throw err; | ||
console.log(name + " created."); | ||
}); | ||
} | ||
|
||
function updateJob(name, content) { | ||
|
||
jenkins.job.config(name, content, function(err) { | ||
if (err) throw err; | ||
console.log(name + " updated."); | ||
}); | ||
} | ||
|
||
function replacePlaceholder(str) { | ||
return str.replace(new RegExp('#GIT_GROUP#', 'g'), gitGroup) | ||
.replace(new RegExp('#GIT_REPO#', 'g'), gitRepo) | ||
.replace(new RegExp('#PROJECT_NAME#', 'g'), projectName) | ||
.replace(new RegExp('#ARTIFACT_GROUP#', 'g'), artifactGroup) | ||
.replace(new RegExp('#ARTIFACT_ID#', 'g'), artifactId); | ||
} | ||
|
||
getAllJobs(); | ||
}); |