blob: 8891fce405a9f3d40a97c3d0054f7a76307e776f [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']) {
Charles Chan89e04a42022-02-03 22:55:19 -080050 sh( script: """
51 #!/usr/bin/env bash
52 set -eu -o pipefail
pierventre4a959602020-11-02 14:46:19 +010053
Charles Chan89e04a42022-02-03 22:55:19 -080054 # checked out in a subdir so the log can be in WORKSPACE
55 cd "$GERRIT_PROJECT"
pierventre4a959602020-11-02 14:46:19 +010056
Charles Chan89e04a42022-02-03 22:55:19 -080057 # set registry/repository variables
58 export DOCKER_REGISTRY="$dockerRegistry/"
59 export DOCKER_REPOSITORY="$dockerRepo"
pierventre4a959602020-11-02 14:46:19 +010060
Charles Chan89e04a42022-02-03 22:55:19 -080061 # Builds having a build date
62 if [ ! -z "$buildDate" ]; then
63 export DOCKER_TAG_BUILD_DATE="-$current_date"
64 fi
pierventre9692bbf2020-11-12 14:34:31 +010065
Charles Chan89e04a42022-02-03 22:55:19 -080066 # Builds having the profiler enabled
67 if [ ! -z "$PROFILER" ]; then
68 export DOCKER_TAG_PROFILER="-profiler"
69 fi
pierventre10be3042021-05-05 18:43:24 +020070
Charles Chan89e04a42022-02-03 22:55:19 -080071 # Build w/extraEnvironmentVars
72 echo "Building image with following vars $extraEnvironmentVars"
73 $extraEnvironmentVars make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
74 """)
pierventre4a959602020-11-02 14:46:19 +010075 }
76 }
77 }
78 }
79 }
80
81 stage('push'){
82 steps {
83 script {
Charles Chan89e04a42022-02-03 22:55:19 -080084 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
pierventre4a959602020-11-02 14:46:19 +010085 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/"
Charles Chan89e04a42022-02-03 22:55:19 -080094 export DOCKER_REPOSITORY="$dockerRepo"
pierventre4a959602020-11-02 14:46:19 +010095
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}