blob: c0feef5780a39890d1876250708814d0af58d065 [file] [log] [blame]
pierventre4a959602020-11-02 14:46:19 +01001// Copyright 2020-present Open Networking Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/* tost-onos-publish pipeline.*/
16pipeline {
17
18 /* executor is determined by JJB */
19 agent {
20 label "${params.buildNode}"
21 }
22
23 /* lighweight version of the docker-publish pipeline. */
24 stages {
25
26 stage('checkout') {
27 steps {
28 checkout([
29 $class: 'GitSCM',
30 userRemoteConfigs: [[ url: "${params.gitUrl}", credentialsId: 'onos-jenkins-ssh', refspec: "$GERRIT_REFSPEC"]],
31 branches: [[ name: "$GERRIT_PATCHSET_REVISION", ]],
32 extensions: [
33 [$class: 'WipeWorkspace'],
34 [$class: 'RelativeTargetDirectory', relativeTargetDir: "$GERRIT_PROJECT"],
35 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
36 [$class: 'SubmoduleOption', recursiveSubmodules: true],
37 ],
38 ])
39 script {
pierventre9692bbf2020-11-12 14:34:31 +010040 current_date = sh(returnStdout: true, script: 'date +%Y-%m-%d').trim()
pierventre4a959602020-11-02 14:46:19 +010041 }
42 }
43 }
44
45 stage('build'){
46 steps {
47 script {
48 sshagent(credentials: ['github-onf-bot-ssh-key']) {
49 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
50 sh( script: """
51 #!/usr/bin/env bash
52 set -eu -o pipefail
53
54 # checked out in a subdir so the log can be in WORKSPACE
55 cd "$GERRIT_PROJECT"
56
57 # set registry/repository variables
58 export DOCKER_REGISTRY="$dockerRegistry/"
59 export DOCKER_REPOSITORY="$dockerRepo/"
60
pierventre9692bbf2020-11-12 14:34:31 +010061 # Builds having a build date
62 if [ ! -z "$buildDate" ]; then
63 export DOCKER_TAG_BUILD_DATE="-$current_date"
64 fi
65
pierventre10be3042021-05-05 18:43:24 +020066 # Builds having the profiler enabled
67 if [ ! -z "$PROFILER" ]; then
68 export DOCKER_TAG_PROFILER="-profiler"
69 fi
70
pierventre4a959602020-11-02 14:46:19 +010071 # Build w/extraEnvironmentVars
72 echo "Building image with following vars $extraEnvironmentVars"
73 $extraEnvironmentVars make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
74 """)
75 }
76 }
77 }
78 }
79 }
80
81 stage('push'){
82 steps {
83 script {
84 withDockerRegistry(credentialsId: 'aether-internal-registry', url: "https://${params.dockerRegistry}") {
85 sh( script:"""
86 #!/usr/bin/env bash
87 set -eu -o pipefail
88
89 # checked out in a subdir so the log can be in WORKSPACE
90 cd "$GERRIT_PROJECT"
91
92 # set registry/repository variables
93 export DOCKER_REGISTRY="$dockerRegistry/"
94 export DOCKER_REPOSITORY="$dockerRepo/"
95
pierventre10be3042021-05-05 18:43:24 +020096 # Builds having a build date
97 if [ ! -z "$buildDate" ]; then
98 export DOCKER_TAG_BUILD_DATE="-$current_date"
99 fi
100
101 # Builds having the profiler enabled
102 if [ ! -z "$PROFILER" ]; then
103 export DOCKER_TAG_PROFILER="-profiler"
104 fi
pierventre9692bbf2020-11-12 14:34:31 +0100105
pierventre4a959602020-11-02 14:46:19 +0100106 # Push w/extraEnvironmentVars
107 echo "Pushing image with following vars $extraEnvironmentVars"
108 $extraEnvironmentVars make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
109 """)
110 }
111 }
112 }
113 }
114 }
115
116 post {
117 always {
118 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
119 deleteDir()
120 }
121 failure {
122 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
123 }
124 }
125}