Merge branch 'branchfrom--juju-charms'
[osm/devops.git] / jenkins / system / Jenkinsfile
1 // input parameters:
2 //   boolean: BUILD_FROM_SOURCE
3 //   boolean: REPO_DISTRO
4 //   boolean: COMMIT_ID
5 //   boolean: UPSTREAM_SUFFIX
6 //   string:  NODE
7 //   string: RSYNC_DESTINATION
8 //   string: REPO_BASE_URL
9 //   string: REPO_KEY_NAME
10 //   string: RELEASE
11
12 node("${params.NODE}") {
13
14     stage("Setup") {
15         tag_or_branch = params.COMMIT_ID.replaceAll(/\./,"")
16         container_name_prefix = "osm-${tag_or_branch}"
17         container_name = "${container_name_prefix}-${BUILD_NUMBER}"
18     }
19
20     stage("Checkout") {
21         checkout scm
22     }
23
24     // Copy the artifacts from the upstream jobs
25     stage("Copy Artifacts") {
26         // cleanup any previous repo
27         sh 'rm -rf repo'
28
29         dir('repo') {
30             // grab all stable upstream builds based on the
31             // given target UPSTREAM_SUFFIX
32
33             def list = ["SO", "UI", "RO", "openvim", "osmclient"]
34             for (component in list) {
35                 step ([$class: 'CopyArtifact',
36                        projectName: "${component}_${params.UPSTREAM_SUFFIX}"])
37                 sh "dpkg-sig --sign builder -k dpkg1 pool/${component}/*"
38                 // cleanup any prevously defined dists
39                 sh "rm -rf dists"
40             }
41
42             // now create the distro
43             for (component in list) {
44                 sh "mkdir -p dists/${params.REPO_DISTRO}/${component}/binary-amd64/"
45                 sh "apt-ftparchive packages pool/${component} > dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
46                 sh "gzip -9fk dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
47             }
48
49             // create and sign the release file
50             sh "apt-ftparchive release dists/${params.REPO_DISTRO} > dists/${params.REPO_DISTRO}/Release"
51             sh "gpg --yes -abs -u dpkg1 -o dists/${params.REPO_DISTRO}/Release.gpg dists/${params.REPO_DISTRO}/Release"
52             sh "rsync -avz . ${params.RSYNC_DESTINATION}/${params.RELEASE}"
53         }
54     }
55
56     stage("Cleanup") {
57         // check for previous containers and clean them up
58         sh "jenkins/system/delete_old_containers.sh ${container_name_prefix}"
59     }
60
61     stage("Build") {
62         from_source = ''
63         if ( params.BUILD_FROM_SOURCE )
64         {
65             from_source = '--source'
66         }
67  
68         sh """
69             export OSM_USE_LOCAL_DEVOPS=true
70             jenkins/host/start_build system --build-container ${container_name} \
71                                             -b ${params.COMMIT_ID} \
72                                             -r ${params.REPO_DISTRO} \
73                                             -u ${params.REPO_BASE_URL} \
74                                             -k ${params.REPO_KEY_NAME} \
75                                             -R ${params.RELEASE} \
76                                             ${from_source}
77            """
78     }
79
80     stage("Archive Artifacts") {
81         sh "echo ${container_name} > build_version.txt"
82         sh "tar -zcvf repo.tar.gz repo"
83         archiveArtifacts artifacts: "build_version.txt, repo.tar.gz", fingerprint: true
84     }
85 }