diff options
Diffstat (limited to 'Jenkinsfile')
-rw-r--r-- | Jenkinsfile | 185 |
1 files changed, 108 insertions, 77 deletions
diff --git a/Jenkinsfile b/Jenkinsfile index bf06986..50e0d09 100644 --- a/Jenkinsfile +++ b/Jenkinsfile | |||
@@ -1,84 +1,115 @@ | |||
1 | // Defining the closure to be used for building a target | 1 | port groovy.io.FileType |
2 | 2 | ||
3 | def target_build = {machine-> | 3 | @NonCPS def getTargets(){ |
4 | print "This is the build for target $machine" | 4 | targetList = [] |
5 | // sh 'mkdir $machine' | 5 | dirList = new File(pwd()+'/manifest_repo/.repo/manifests/') |
6 | // dir ('$machine') { | 6 | dirList.eachFile { file -> if (file.directory && file.name!='.git' && file.name!='common'){targetList.add file.name}} |
7 | // pwd() | 7 | return targetList |
8 | // unstash 'eltf_scripts' | 8 | } |
9 | // } | ||
10 | } | ||
11 | 9 | ||
12 | def constructor_function(trg) {{it->print "This is another build for the target $trg"}} | 10 | def targetBuild(trg){ |
13 | 11 | { | |
14 | node { | 12 | target=trg-> node{ |
15 | // Start the fist stage which sets up the pipeline environment | 13 | sh 'mkdir trg' |
16 | stage 'Set up environment' | 14 | dir ('$trg'){ |
17 | // Cleaning the workspace | 15 | unstash 'eltf_scripts' |
18 | deleteDir() | 16 | checkout([$class: 'RepoScm', |
19 | 17 | currentBranch: true, | |
20 | // The first step is to freeze the manifest repositiries | 18 | manifestBranch: '$BRANCH_NAME', |
21 | print "To add a job to freeze the manifest repositories" | 19 | manifestFile: '$trg/default.xml', |
22 | 20 | //The hardcoded repository should be replaced by a generic name, eg. $GIT_PATH+el_manifests-$PROFILE | |
23 | def targets = TARGET_LIST.split(',') | 21 | manifestRepositoryUrl: 'http://git.enea.se/cgit/various/el_manifests-standard.git', |
24 | for (item in targets) {print item} | 22 | quiet: true, |
25 | 23 | showAllChanges: true, | |
26 | // Old implementation of the git clone. Changed as it does not support target directory | 24 | trace: true]) |
27 | //git url: 'git@git.enea.se:eltf/scripts.git', branch: 'master', relativeTargetDir: 'eltf_scripts' | 25 | checkout([$class: 'GitSCM', |
28 | 26 | branches: [[name: '$BRANCH_NAME']], | |
29 | // Clone eltf/scripts.git repository | 27 | doGenerateSubmoduleConfigurations: false, |
30 | checkout([$class: 'GitSCM', | 28 | extensions: [[$class: 'RelativeTargetDirectory', |
31 | branches: [[name: '*/master']], | 29 | relativeTargetDir: 'poky/'], |
32 | doGenerateSubmoduleConfigurations: false, | 30 | [$class: 'AuthorInChangelog']], |
33 | extensions: [[$class: 'RelativeTargetDirectory', | 31 | submoduleCfg: [], |
34 | relativeTargetDir: 'eltf_scripts']], | 32 | userRemoteConfigs: [[credentialsId: 'a797f854-983e-473e-b221-6d8ebafda16a', |
35 | submoduleCfg: [], | 33 | url: 'git@git.enea.se:linux/meta-enea-test.git']]]) |
36 | userRemoteConfigs: [[url: 'git@git.enea.se:eltf/scripts.git']]]) | 34 | } |
37 | 35 | } | |
38 | // Stash the ELTF scripts in order to be used on other nodes | 36 | } |
39 | stash includes: 'eltf_scripts/*', name: 'eltf_scripts', useDefaultExcludes: false | 37 | } |
40 | |||
41 | // Start the next stages for Build, Test and Document | ||
42 | |||
43 | stage 'Build' | ||
44 | 38 | ||
45 | build_jobs = [:] | 39 | /* |
46 | for (item in targets){build_jobs.put(item, constructor_function(item))} | 40 | Defining the first stage of the pipeline. |
47 | print "I am here" | 41 | This stage prepares the workspace and the build environment, clones ELTF scripts and |
42 | stashes them in order to be used on all distrubuted nodes. | ||
43 | This stage is also determining needed information like the targets to be built/tested. | ||
44 | */ | ||
48 | 45 | ||
49 | try { | 46 | stage 'Environment Setup' |
50 | parallel build_jobs | 47 | node { |
51 | } | 48 | // Delete workspace content before running any step |
52 | catch (java.io.NotSerializableException stupid_error){ | 49 | deleteDir() |
50 | |||
51 | // Freeze manifest files before running builds | ||
52 | print "To add a job to freeze the manifest repositories" | ||
53 | |||
54 | // Clone eltf/scripts.git repository | ||
55 | checkout([$class: 'GitSCM', | ||
56 | branches: [[name: '*/master']], | ||
57 | doGenerateSubmoduleConfigurations: false, | ||
58 | extensions: [[$class: 'RelativeTargetDirectory',relativeTargetDir: 'eltf_scripts']], | ||
59 | submoduleCfg: [], | ||
60 | userRemoteConfigs: [[url: 'git@git.enea.se:eltf/scripts.git']]]) | ||
53 | 61 | ||
54 | 1,1 Top | 62 | // Stash the ELTF scripts in order to be used on other nodes |
55 | print "Finished parallel step and entered the catch statement" | 63 | stash includes: 'eltf_scripts/*', name: 'eltf_scripts', useDefaultExcludes: false |
56 | print stupid_error | ||
57 | //stage 'Test' | ||
58 | print "hello from stage 3" | ||
59 | } | ||
60 | try { | ||
61 | stage 'Document' | ||
62 | print "hello from stage 4" | ||
63 | stage 'Build Documentation' | ||
64 | print "hello from stage 5" | ||
65 | stage 'Build Release Candidate' | ||
66 | echo "hello...it's me...:)" | ||
67 | stage 'Publish Release Candidate' | ||
68 | def PUBLISH_RC = input( | ||
69 | id: 'PUBLISH_RC', message: 'Publish RC?', ok: 'Yes', parameters: [ | ||
70 | [$class: 'StringParameterDefinition', defaultValue: 'RC1', description: 'This is the RC number to be published', name: 'RC_NUMBER'], | ||
71 | [$class: 'StringParameterDefinition', defaultValue: 'EL6_RC2', description: 'This is the tag to be applied in the manifest repo', name: 'RC_TAG'] | ||
72 | ]) | ||
73 | echo ("The RC number is: "+PUBLISH_RC['RC_NUMBER']) | ||
74 | print "hello from stage 5" | ||
75 | echo ("The RC number is: "+PUBLISH_RC['RC_NUMBER']) | ||
76 | stage 'Pubilsh Official Release' | ||
77 | echo ("The RC number is: "+PUBLISH_RC['RC_NUMBER']) | ||
78 | } | ||
79 | catch (err) { | ||
80 | print err | ||
81 | } | ||
82 | } | ||
83 | 64 | ||
65 | // Clone manifest repository in order to determine target list | ||
66 | checkout([$class: 'RepoScm', | ||
67 | currentBranch: true, | ||
68 | destinationDir: 'manifest_repo', | ||
69 | manifestBranch: 'master', | ||
70 | manifestRepositoryUrl: 'http://git.enea.se/cgit/various/el_manifests-standard.git', | ||
71 | showAllChanges: true, | ||
72 | trace: true]) | ||
73 | |||
74 | // Parse directory structure in order to determine the target list | ||
75 | targetList = getTargets() | ||
76 | for (item in targetList) {print item} | ||
77 | |||
78 | print 'Finished stage Environment Setup' | ||
79 | } | ||
84 | 80 | ||
81 | stage 'Build' | ||
82 | // Create the build map which defines the build threads | ||
83 | def buildMap = [:] | ||
84 | for (item in targetList){ | ||
85 | def id = item+'_build' | ||
86 | buildMap[id] = targetBuild(item) | ||
87 | } | ||
88 | parallel buildMap | ||
89 | node { | ||
90 | print 'Finished stage Build' | ||
91 | } | ||
92 | stage 'Test' | ||
93 | node { | ||
94 | print 'Finished stage Test' | ||
95 | } | ||
96 | stage 'Document' | ||
97 | node { | ||
98 | print 'Finished stage Document' | ||
99 | } | ||
100 | stage 'Build Documentation' | ||
101 | node { | ||
102 | print 'Finished stage Build Documentation' | ||
103 | } | ||
104 | stage 'Build Release Candidate' | ||
105 | node { | ||
106 | print 'Finished stage Build RC' | ||
107 | } | ||
108 | stage 'Publish Release Candidate' | ||
109 | node { | ||
110 | print 'Finished stage Publish RC' | ||
111 | } | ||
112 | stage 'Publish official Release' | ||
113 | node { | ||
114 | print 'Finished stage Publish Release' | ||
115 | } | ||