From 32ca93c38b4c949ddfdd518ad81ca2caabb30f1d Mon Sep 17 00:00:00 2001 From: Andrei Gheorghiu Date: Thu, 15 Sep 2016 10:16:29 +0200 Subject: updated Jenkinsfile --- Jenkinsfile | 196 +++++------------------------------------------------------- 1 file changed, 15 insertions(+), 181 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 971a250..e8beaac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,184 +1,18 @@ -import groovy.io.FileType -//=====USER DEFINED VARIABLES===== -def images_to_buid = ['enea-image-'+profile, 'enea-image-'+profile+'-sdk', 'world'] -def localGitRoot = 'http://git.enea.se/cgit/various/' -def publicGitRoot = 'http://git.enea.com/cgit/linux/' - -//=====USER DEFINED FUNCTIONS===== - -def getProfile(){ - return 'standard' -} - -def getReleaseLayer(){ - releaseLayer = 'meta-el-'+getProfile() - return releaseLayer -} - -@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 imageBuild(imageType, machine, profile, buildStamp, releaseLayer){ - { - it-> node{ - print 'Starting build for each image type '+imageType - print machine - print profile - print buildStamp - print releaseLayer - print pwd() - dir (trg){ - unstash machine+'_poky' - } - } - } -} - -def targetBuild(trg, images_to_buid, profile, buildStamp, releaseLayer){ - { - 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]) - print 'Finished cloning with Repo tool' - 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']]]) - print 'Finished cloing meta-enea-test' - print pwd() - dir (poky){ - stash trg+'_poky' - } - } +#!/bin/env groovy + +stage "Loading Sripts" + +node ('master') { + print 'master node' + dir ("../${env.BRANCH_NAME}@script") { + def git_remote_url = sh returnStdout: true, script: "git remote get-url origin" + def git_repo = git_remote_url.trim().split('/')[-1] + def git_repo_name = git_repo.replace('.git','') + def profile = git_repo_name.split('-')[-1] + env.PROFILE = profile + sh 'echo $PROFILE' } - def buildImageMap = [:] - for (image in images_to_buid){ - def imageId = 'build_'+image+'_for_'+trg - buildImageMap[imageId] = imageBuild(imageId, trg, profile, buildStamp, releaseLayer) - } - parallel buildImageMap - } -} - -//=====ENVIRONMENT SETUP===== - -/* -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. -*/ - -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']]]) - - // 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() - - // Determine needed information like the EL Profile or the release layer to be used later as environment variables - profile = getProfile() - releaseLayer = getReleaseLayer() - buildStamp = env.BUILD_TIMESTAMP - print profile - print releaseLayer - print buildStamp - - - print 'Finished stage Environment Setup' -} - -//=====BUILD===== - -/* -Defining the seond stage of the pipeline, the Build stege -This stage defines the threads to be run in parallel for each target, based on -the list of targets identified in previous stage. It then runs each thread in -parallel. The steps in each thread are defined in the closure retuned by the -targetBuild function. When all parallel threads are finished, a message is -printed on the console. -*/ - -stage 'Build' -// Create the build map which defines the build threads -def buildTargetMap = [:] -for (item in targetList){ - def id = item+'_build' - buildTargetMap[id] = targetBuild(item, images_to_buid, profile, buildStamp, releaseLayer) -} -// Run threads for each target in parallel -parallel buildTargetMap - -node { - print 'Finished stage Build' -} - -//=====TEST===== - -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' +fileLoader.withGit('git@git.enea.se:eltf/jenkins.git', 'master', null, '') { + fileLoader.load('el_pipeline.groovy'); } -- cgit v1.2.3-54-g00ecf