From 22b47078158182d94f567ea5f1f569c3f4189c4c Mon Sep 17 00:00:00 2001 From: Catalin Scrieciu Date: Thu, 14 Jul 2016 14:44:48 +0200 Subject: test --- Jenkinsfile | 185 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 108 insertions(+), 77 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bf06986..50e0d09 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,84 +1,115 @@ -// Defining the closure to be used for building a target +port groovy.io.FileType -def target_build = {machine-> - print "This is the build for target $machine" - // sh 'mkdir $machine' - // dir ('$machine') { - // pwd() - // unstash 'eltf_scripts' - // } - } +@NonCPS def getTargets(){ + targetList = [] + dirList = new File(pwd()+'/manifest_repo/.repo/manifests/') + dirList.eachFile { file -> if (file.directory && file.name!='.git' && file.name!='common'){targetList.add file.name}} + return targetList +} -def constructor_function(trg) {{it->print "This is another build for the target $trg"}} - -node { - // Start the fist stage which sets up the pipeline environment - stage 'Set up environment' - // Cleaning the workspace - deleteDir() - - // The first step is to freeze the manifest repositiries - print "To add a job to freeze the manifest repositories" - - def targets = TARGET_LIST.split(',') - for (item in targets) {print item} - - // Old implementation of the git clone. Changed as it does not support target directory - //git url: 'git@git.enea.se:eltf/scripts.git', branch: 'master', relativeTargetDir: 'eltf_scripts' - - // Clone eltf/scripts.git repository - checkout([$class: 'GitSCM', - branches: [[name: '*/master']], - doGenerateSubmoduleConfigurations: false, - extensions: [[$class: 'RelativeTargetDirectory', - relativeTargetDir: 'eltf_scripts']], - submoduleCfg: [], - userRemoteConfigs: [[url: 'git@git.enea.se:eltf/scripts.git']]]) - - // Stash the ELTF scripts in order to be used on other nodes - stash includes: 'eltf_scripts/*', name: 'eltf_scripts', useDefaultExcludes: false - - // Start the next stages for Build, Test and Document - - stage 'Build' +def targetBuild(trg){ + { + target=trg-> node{ + sh 'mkdir trg' + dir ('$trg'){ + unstash 'eltf_scripts' + checkout([$class: 'RepoScm', + currentBranch: true, + manifestBranch: '$BRANCH_NAME', + manifestFile: '$trg/default.xml', + //The hardcoded repository should be replaced by a generic name, eg. $GIT_PATH+el_manifests-$PROFILE + manifestRepositoryUrl: 'http://git.enea.se/cgit/various/el_manifests-standard.git', + quiet: true, + showAllChanges: true, + trace: true]) + checkout([$class: 'GitSCM', + branches: [[name: '$BRANCH_NAME']], + doGenerateSubmoduleConfigurations: false, + extensions: [[$class: 'RelativeTargetDirectory', + relativeTargetDir: 'poky/'], + [$class: 'AuthorInChangelog']], + submoduleCfg: [], + userRemoteConfigs: [[credentialsId: 'a797f854-983e-473e-b221-6d8ebafda16a', + url: 'git@git.enea.se:linux/meta-enea-test.git']]]) + } + } + } +} - build_jobs = [:] - for (item in targets){build_jobs.put(item, constructor_function(item))} - print "I am here" +/* +Defining the first stage of the pipeline. +This stage prepares the workspace and the build environment, clones ELTF scripts and +stashes them in order to be used on all distrubuted nodes. +This stage is also determining needed information like the targets to be built/tested. +*/ - try { - parallel build_jobs - } - catch (java.io.NotSerializableException stupid_error){ +stage 'Environment Setup' +node { + // Delete workspace content before running any step + deleteDir() + + // Freeze manifest files before running builds + print "To add a job to freeze the manifest repositories" + + // Clone eltf/scripts.git repository + checkout([$class: 'GitSCM', + branches: [[name: '*/master']], + doGenerateSubmoduleConfigurations: false, + extensions: [[$class: 'RelativeTargetDirectory',relativeTargetDir: 'eltf_scripts']], + submoduleCfg: [], + userRemoteConfigs: [[url: 'git@git.enea.se:eltf/scripts.git']]]) - 1,1 Top - print "Finished parallel step and entered the catch statement" - print stupid_error - //stage 'Test' - print "hello from stage 3" - } - try { - stage 'Document' - print "hello from stage 4" - stage 'Build Documentation' - print "hello from stage 5" - stage 'Build Release Candidate' - echo "hello...it's me...:)" - stage 'Publish Release Candidate' - def PUBLISH_RC = input( - id: 'PUBLISH_RC', message: 'Publish RC?', ok: 'Yes', parameters: [ - [$class: 'StringParameterDefinition', defaultValue: 'RC1', description: 'This is the RC number to be published', name: 'RC_NUMBER'], - [$class: 'StringParameterDefinition', defaultValue: 'EL6_RC2', description: 'This is the tag to be applied in the manifest repo', name: 'RC_TAG'] - ]) - echo ("The RC number is: "+PUBLISH_RC['RC_NUMBER']) - print "hello from stage 5" - echo ("The RC number is: "+PUBLISH_RC['RC_NUMBER']) - stage 'Pubilsh Official Release' - echo ("The RC number is: "+PUBLISH_RC['RC_NUMBER']) - } - catch (err) { - print err - } - } + // Stash the ELTF scripts in order to be used on other nodes + stash includes: 'eltf_scripts/*', name: 'eltf_scripts', useDefaultExcludes: false + // Clone manifest repository in order to determine target list + checkout([$class: 'RepoScm', + currentBranch: true, + destinationDir: 'manifest_repo', + manifestBranch: 'master', + manifestRepositoryUrl: 'http://git.enea.se/cgit/various/el_manifests-standard.git', + showAllChanges: true, + trace: true]) + + // Parse directory structure in order to determine the target list + targetList = getTargets() + for (item in targetList) {print item} + + print 'Finished stage Environment Setup' +} +stage 'Build' +// Create the build map which defines the build threads +def buildMap = [:] +for (item in targetList){ + def id = item+'_build' + buildMap[id] = targetBuild(item) +} +parallel buildMap +node { + print 'Finished stage Build' +} +stage 'Test' +node { + print 'Finished stage Test' +} +stage 'Document' +node { + print 'Finished stage Document' +} +stage 'Build Documentation' +node { + print 'Finished stage Build Documentation' +} +stage 'Build Release Candidate' +node { + print 'Finished stage Build RC' +} +stage 'Publish Release Candidate' +node { + print 'Finished stage Publish RC' +} +stage 'Publish official Release' +node { + print 'Finished stage Publish Release' +} -- cgit v1.2.3-54-g00ecf