blob: b8be9318c3d129b442c6a6bb6ca5a390ca68d43c [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
Carmelo Cascone79805492022-02-04 17:27:21 -080015def dockerRegistry = params.dockerRegistry ? "${params.dockerRegistry}/" : ""
16
Charles Chanf73d2402022-02-09 22:38:19 -080017/* sdfabric-onos-publish pipeline.*/
pierventre4a959602020-11-02 14:46:19 +010018pipeline {
19
20 /* executor is determined by JJB */
21 agent {
22 label "${params.buildNode}"
23 }
24
25 /* lighweight version of the docker-publish pipeline. */
26 stages {
27
28 stage('checkout') {
29 steps {
30 checkout([
31 $class: 'GitSCM',
32 userRemoteConfigs: [[ url: "${params.gitUrl}", credentialsId: 'onos-jenkins-ssh', refspec: "$GERRIT_REFSPEC"]],
33 branches: [[ name: "$GERRIT_PATCHSET_REVISION", ]],
34 extensions: [
35 [$class: 'WipeWorkspace'],
36 [$class: 'RelativeTargetDirectory', relativeTargetDir: "$GERRIT_PROJECT"],
37 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
38 [$class: 'SubmoduleOption', recursiveSubmodules: true],
39 ],
40 ])
41 script {
pierventre9692bbf2020-11-12 14:34:31 +010042 current_date = sh(returnStdout: true, script: 'date +%Y-%m-%d').trim()
pierventre4a959602020-11-02 14:46:19 +010043 }
44 }
45 }
46
47 stage('build'){
48 steps {
49 script {
50 sshagent(credentials: ['github-onf-bot-ssh-key']) {
51 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
Carmelo Cascone79805492022-02-04 17:27:21 -080052 // Required to pull the bf-sde image.
53 withDockerRegistry([url: 'https://registry.opennetworking.org', credentialsId: 'onf-internal-registry']) {
54 sh( script: """
55 #!/usr/bin/env bash
56 set -eu -o pipefail
pierventre4a959602020-11-02 14:46:19 +010057
Carmelo Cascone79805492022-02-04 17:27:21 -080058 # checked out in a subdir so the log can be in WORKSPACE
59 cd "$GERRIT_PROJECT"
pierventre4a959602020-11-02 14:46:19 +010060
Carmelo Cascone79805492022-02-04 17:27:21 -080061 # set registry/repository variables
62 export DOCKER_REGISTRY="$dockerRegistry"
63 export DOCKER_REPOSITORY="$dockerRepo"
pierventre4a959602020-11-02 14:46:19 +010064
Carmelo Cascone79805492022-02-04 17:27:21 -080065 # Builds having a build date
66 if [ ! -z "$buildDate" ]; then
67 export DOCKER_TAG_BUILD_DATE="-$current_date"
68 fi
pierventre9692bbf2020-11-12 14:34:31 +010069
Carmelo Cascone79805492022-02-04 17:27:21 -080070 # Builds having the profiler enabled
71 if [ ! -z "$PROFILER" ]; then
72 export DOCKER_TAG_PROFILER="-profiler"
73 fi
pierventre10be3042021-05-05 18:43:24 +020074
Carmelo Cascone79805492022-02-04 17:27:21 -080075 # Build w/extraEnvironmentVars
76 echo "Building image with following vars $extraEnvironmentVars"
77 $extraEnvironmentVars make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
78 """)
79 }
pierventre4a959602020-11-02 14:46:19 +010080 }
81 }
82 }
83 }
84 }
85
86 stage('push'){
87 steps {
88 script {
Charles Chan89e04a42022-02-03 22:55:19 -080089 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
pierventre4a959602020-11-02 14:46:19 +010090 sh( script:"""
91 #!/usr/bin/env bash
92 set -eu -o pipefail
93
94 # checked out in a subdir so the log can be in WORKSPACE
95 cd "$GERRIT_PROJECT"
96
97 # set registry/repository variables
Carmelo Cascone79805492022-02-04 17:27:21 -080098 export DOCKER_REGISTRY="$dockerRegistry"
Charles Chan89e04a42022-02-03 22:55:19 -080099 export DOCKER_REPOSITORY="$dockerRepo"
pierventre4a959602020-11-02 14:46:19 +0100100
pierventre10be3042021-05-05 18:43:24 +0200101 # Builds having a build date
102 if [ ! -z "$buildDate" ]; then
103 export DOCKER_TAG_BUILD_DATE="-$current_date"
104 fi
105
106 # Builds having the profiler enabled
107 if [ ! -z "$PROFILER" ]; then
108 export DOCKER_TAG_PROFILER="-profiler"
109 fi
pierventre9692bbf2020-11-12 14:34:31 +0100110
pierventre4a959602020-11-02 14:46:19 +0100111 # Push w/extraEnvironmentVars
112 echo "Pushing image with following vars $extraEnvironmentVars"
113 $extraEnvironmentVars make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
114 """)
115 }
116 }
117 }
118 }
119 }
120
121 post {
122 always {
123 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
124 deleteDir()
125 }
126 failure {
127 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
128 }
129 }
130}