Skip to content

Instantly share code, notes, and snippets.

@jdickie
Created September 6, 2016 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdickie/faff5046a9c80f0688e89720dd2e3d8a to your computer and use it in GitHub Desktop.
Save jdickie/faff5046a9c80f0688e89720dd2e3d8a to your computer and use it in GitHub Desktop.
Here the code is going through a folder specified in a Jenkins job string parameter and finding all tests. It iterates through each file and makes a JSON config file that will get read by a downstream Jenkins job that generates tests. A lot of this is based on assumptions about our codebase and we'd like to eventually move on to more robust setu…
def traverseWorkspaceDir(File path, jobs, jobMaster) {
path.traverse { file ->
if (!file.isDirectory() && !(file.name.matches(/^\.[A-z]*/))) {
addFileToJobsList(file, jobs, jobMaster)
}
}
}
def addFileToJobsList(File file, jobs, jobMaster) {
curJob = new Job()
curJob.name = BASE_TEST_NAME + "Api_" + file.name.replaceAll(/\.[a-z]*$/, "")
curJob.testPath = file.getPath().replaceAll(/[\/A-z0-4\-]*\/unittest/, ".")
curJob.testName = file.name
curJob.remoteCommand = "cd $DOCROOT\nphp ../../vendor/phpunit/phpunit/phpunit -c phpunit.xml ${curJob.testPath}"
def phaseName = file.getPath().replaceAll(/[\/A-z0-9]+\/api\//, "")
phaseName = phaseName.replaceAll(/\/[A-z]*\.php/, "")
if (!jobMaster.phases.contains(phaseName)) {
jobMaster.phases << phaseName
}
jobMaster.jobs << phaseName + "|" + curJob.name
jobs << curJob
}
def writeJsonToFile(String json) {
new File("${WORKSPACE}/nprDSL/configs").mkdir()
new File("${CONFIG_FOLDER_PATH}").withWriter('utf-8') { writer ->
writer.write(json)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment