add pipeline stages
[test.git] / Jenkinsfile
1 def Get_MDG(project) {
2     // split the project.
3     def values = project.split('/')
4     if ( values.size() > 1 ) {
5         return values[1]
6     }
7     // no prefix, likely just the project name then
8     return project
9 }
10
11 def project_checkout() {
12     // checkout the project
13     git url: "https://osm.etsi.org/gerrit/${GERRIT_PROJECT}"
14
15     sh "git fetch origin ${GERRIT_REFSPEC}"
16     if (GERRIT_PATCHSET_REVISION.size() > 0 ) {
17         sh "git checkout -f ${GERRIT_PATCHSET_REVISION}"
18     }
19 }
20
21 def devops_checkout() {
22     dir('devops') {
23         git url: 'https://osm.etsi.org/gerrit/osm/devops'
24     }
25 }
26
27 node {
28     stage('Prepare') {
29         sh 'env'
30         devops_checkout()
31     }
32
33     stage('Checkout') {
34         project_checkout()
35     }
36
37     container_name = "${GERRIT_PROJECT}-${GERRIT_BRANCH}"
38
39     mdg = Get_MDG("${GERRIT_PROJECT}")
40     println("MDG is ${mdg}")
41
42     stage('Docker-Build') {
43         sh "docker build -t ${container_name} ."
44     }
45
46     withDockerContainer("${container_name}") {
47         stage('Docker-Setup') {
48             sh '''
49                groupadd -o -g $(id -g) -r jenkins
50                useradd -o -u $(id -u) --create-home -r -g  jenkins jenkins
51                '''
52         }
53         stage('Test') {
54             sh 'devops-stages/stage-test.sh'
55         }
56         stage('Build') {
57             sh 'devops-stages/stage-build.sh'
58         }
59         stage('Archive') {
60             sh 'devops-stages/stage-archive.sh'
61             archiveArtifacts artifacts: "dists/**,pool/${mdg}/*.deb", fingerprint: true
62         }
63     }
64 }