Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #19 from cdit-ma/develop
Browse files Browse the repository at this point in the history
a
  • Loading branch information
danielrfraser authored Nov 16, 2017
2 parents 2464f53 + 758b2c8 commit 9a15d63
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 141 deletions.
37 changes: 37 additions & 0 deletions jenkins/build_logan.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def PROJECT_NAME = 'test_logan'
//Load shared pipeline utility library
@Library('cditma-utils')
import cditma.Utils

def utils = new Utils(this);

stage("Checkout"){
node("master"){
dir(PROJECT_NAME){
checkout scm
}
stash includes: "**", name: "source_code"
}
}

def step_build_test = [:]
def step_test = [:]

def re_nodes = utils.getLabelledNodes("build_logan")
for(n in re_nodes){
def node_name = n

step_build_test[node_name] = {
node(node_name){
unstash "source_code"
dir(PROJECT_NAME + "/build"){
//Build the entire project
utils.buildProject("Unix Makefiles", "")
}
}
}
}

stage("Build"){
parallel step_build_test
}
169 changes: 28 additions & 141 deletions jenkins/deploy_logan.groovy
Original file line number Diff line number Diff line change
@@ -1,162 +1,49 @@
/**
This script will deploy logan to all jenkins slaves with the logan label.
This script requires the following Jenkins parameters:
- "GIT_CREDENTIAL_ID" : Username with password credential
- "GIT_URL" : String parameter (Defaulted to https://github.com/cdit-ma/logan)
- "GIT_BRANCH" : Optional branch to checkout, overridden by GIT_TAG
- "GIT_TAG" : Optional version tag, ignores any branch specified
This script requires the following Jenkins plugins:
-Pipeline: Utility Steps
*/

def PROJECT_NAME = 'logan'

// This method collects a list of Node names from the current Jenkins instance
@NonCPS
def nodeNames() {
return jenkins.model.Jenkins.instance.nodes.collect { node -> node.name }
}

//Gets nodes label
def getLabels(String name){
def computer = Jenkins.getInstance().getComputer(name)
def node = computer.getNode()
if(computer.isOnline()){
return node.getLabelString()
}
return ""
}

//Check all required params
def checkParamsExist(){
def git_url = ""
git_url = env.GIT_URL
if(git_url == null){
print("ERROR: \"GIT_URL\" string parameter missing in build configuration")
return false
}
def git_credential_id = ""
git_credential_id = env.GIT_CREDENTIAL_ID
if(git_credential_id == null) {
print("ERROR: \"GIT_CREDENTIAL_ID\" credential parameter missing in build configuration")
return false
}
def branch = env.GIT_BRANCH
if(branch == null){
print("ERROR: \"GIT_BRANCH\" string parameter missing in build configuration")
return false
}

def tag = env.GIT_TAG
if(tag == null){
print("ERROR: \"GIT_TAG\" string parameter missing in build configuration")
return false
}

return true
}

def getCredentialID(){
return env.GIT_CREDENTIAL_ID
}

//Build git ref pointer. If no branch specified, use tag, if no tag specified use default branch (master).
def buildGitRef(String branch, String tag){
def default_branch = "master"
def ref_name = ""

if(!branch){
branch = default_branch
}
ref_name = "*/" + branch
//Load shared pipeline utility library
@Library('cditma-utils')
import cditma.Utils

if(tag){
ref_name = "refs/tags/" + tag
}
return ref_name
}

//Build git url. If no url specified, default to cdit-ma github+proj name
def buildGitUrl(String url, String proj){
def default_git_url = "https://github.com/cdit-ma/" + proj + ".git"
//Set git url to default if empty
if(!url){
return default_git_url
}
return url
}
def utils = new Utils(this);

def PROJECT_NAME = 'logan'
def git_url = "/srv/git"
def logan_nodes = utils.getLabelledNodes(PROJECT_NAME);

def ref_name = ""
def git_url = ""
def git_credential_id = ""
def filtered_names = []

stage('Set up'){
//Start deploy script
if(!checkParamsExist()){
currentBuild.result = 'FAILURE'
return
}

//Get nodes to deploy to
def names = nodeNames()
for(n in names){
if(getLabels(n).contains(PROJECT_NAME)){
filtered_names << n
print("Got Node: " + n)
}
}

//Build git url and ref
git_credential_id = getCredentialID()
git_url = buildGitUrl(env.GIT_URL, PROJECT_NAME)
ref_name = buildGitRef(env.GIT_BRANCH, env.GIT_TAG)
currentBuild.description = git_url + '/' + ref_name
}

//Checkout logan on master node and stash
//Checkout and stash logan source (stored on Master's local git repo)
stage('Checkout'){
node("master"){
dir("logan"){
deleteDir()
checkout([$class: 'GitSCM', branches: [[name: ref_name]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: false, reference: '', trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: git_credential_id, url: git_url]]])
stash includes: "**", name: "logan_source"
node('master'){
dir(git_url + "/" + PROJECT_NAME){
stash include: "**", name: "source_code"
}
}
}

//Unstash on all logan nodes
stage('Checkout'){
def builders = [:]
for(n in filtered_names){
def node_name = n
builders[node_name] = {
node(node_name){
def loganPath = "${LOGAN_PATH}"
dir(loganPath){
unstash "logan_source"
//Construct build map for all nodes which should build
def step_build = [:]
for(n in logan_nodes){
def node_name = n
step_build[node_name] = {
node(node_name){
dir("${LOGAN_PATH}"){
deleteDir()
unstash "source_code"
dir("build"){
def result = utils.buildProject("Unix Makefiles", "")
if(!result){
error('Failed to compile')
}
}
}
}
}
parallel builders
}

//Build on all logan nodes
//Build logan on all logan nodes
stage('Build'){
def builders = [:]
for(n in filtered_names){
def node_name = n
builders[node_name] = {
node(node_name){
def loganPath = "${LOGAN_PATH}"
dir(loganPath + '/build'){
sh 'cmake ..'
sh 'make -j6'
}
}
}
}
parallel builders
}
parallel step_build
}
17 changes: 17 additions & 0 deletions jenkins/update_logan.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

def git_path = "/srv/git/logan";

//Pull from the setup SCM in Jenkins Job
stage("checkout") {
node("master"){
dir(git_path){
deleteDir();
checkout(scm);
}
}
}

currentBuild.description = env.BRANCH

//Deploy and build
build(job: 'deploy_logan', quietPeriod: 0);

0 comments on commit 9a15d63

Please sign in to comment.