author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 17 Dec 2016 22:22:43 +0000 | |
changeset 106 | af335c19cc3b |
parent 105 | 983a637074e6 |
child 151 | ce9d05ba9205 |
permissions | -rw-r--r-- |
69
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
1 |
/* |
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
2 |
* Run default pipeline. See `pipeline.groovy for details. |
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
3 |
*/ |
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
4 |
|
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
5 |
def pipeline; |
80
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
6 |
|
105
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
7 |
/* |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
8 |
* A helper function to return a branch to build. |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
9 |
* |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
10 |
* For normal jobs this is the value of 'Branch' field from SCM configuration. |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
11 |
* For multibranch jobs, this is the value of BRANCH_NAME environment variable. |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
12 |
* |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
13 |
* This is the same as build() function in `pipeline.groovy` and should be kept |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
14 |
* in sync. We cannot use the one there as we yet have to load it. |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
15 |
*/ |
80
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
16 |
def branch() { |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
17 |
if (env.BRANCH_NAME == null) { |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
18 |
return scm.getBranch(); |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
19 |
} else { |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
20 |
return env.BRANCH_NAME; |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
21 |
} |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
22 |
} |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
23 |
|
69
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
24 |
stage ( "Load Pipeline") { |
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
25 |
node { |
74
57edfcce2a40
Pipeline: use dedicated workspace to checkout and load pipeline script
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
70
diff
changeset
|
26 |
/* |
57edfcce2a40
Pipeline: use dedicated workspace to checkout and load pipeline script
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
70
diff
changeset
|
27 |
* Do not use default workspace here as checkout |
57edfcce2a40
Pipeline: use dedicated workspace to checkout and load pipeline script
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
70
diff
changeset
|
28 |
* would erase all contents. Use a dedicated |
57edfcce2a40
Pipeline: use dedicated workspace to checkout and load pipeline script
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
70
diff
changeset
|
29 |
* workspace instead |
57edfcce2a40
Pipeline: use dedicated workspace to checkout and load pipeline script
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
70
diff
changeset
|
30 |
*/ |
57edfcce2a40
Pipeline: use dedicated workspace to checkout and load pipeline script
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
70
diff
changeset
|
31 |
ws ("workspace/${env.JOB_NAME}@loadpipeline") { |
80
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
32 |
sshagent([ scm.getCredentialsId() ]) { |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
33 |
sh """ |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
34 |
if [ -f pipeline.groovy ]; then |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
35 |
hg pull ${scm.getSource()} |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
36 |
else |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
37 |
hg clone ${scm.getSource()} . |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
38 |
fi |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
39 |
hg up ${branch()} |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
40 |
""" |
c213d491e876
Added feature branch "feature-block-in-context"
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
74
diff
changeset
|
41 |
} |
74
57edfcce2a40
Pipeline: use dedicated workspace to checkout and load pipeline script
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
70
diff
changeset
|
42 |
pipeline = load "pipeline.groovy" |
57edfcce2a40
Pipeline: use dedicated workspace to checkout and load pipeline script
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
70
diff
changeset
|
43 |
} |
69
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
44 |
} |
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
45 |
} |
23cdc822cfc5
Initial support for Jenkins pipelines.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
46 |
|
105
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
47 |
/* |
106
af335c19cc3b
CI: Allow to use different credentials to push to upstream
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
105
diff
changeset
|
48 |
* Set the branch to build to make sure it's in sync |
af335c19cc3b
CI: Allow to use different credentials to push to upstream
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
105
diff
changeset
|
49 |
*/ |
af335c19cc3b
CI: Allow to use different credentials to push to upstream
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
105
diff
changeset
|
50 |
pipeline.branch = branch() |
af335c19cc3b
CI: Allow to use different credentials to push to upstream
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
105
diff
changeset
|
51 |
|
af335c19cc3b
CI: Allow to use different credentials to push to upstream
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
105
diff
changeset
|
52 |
/* |
105
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
53 |
* If we're building a 'default' branch, run "integration" pipeline. Otherwise, |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
54 |
* run normal "build" pipeline, assuming this build is just a test build for |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
55 |
* some feature-in-progress. If different logic is needed, then make a branch |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
56 |
* and modify this file |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
57 |
*/ |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
58 |
if ( branch().equals("default") ) { |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
59 |
pipeline.integration() |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
60 |
} else { |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
61 |
pipeline.build() |
983a637074e6
CI: Revise pipelines, use "integration" pipeline by default
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
80
diff
changeset
|
62 |
} |