blob: 9d6904944d6f8af8300a5f86204958b71d2f50fd [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']) {
Carmelo Cascone108ca5b2021-06-08 13:56:36 -070050 withDockerRegistry([url: 'https://registry.opennetworking.org', credentialsId: 'onf-internal-registry']) {
51 sh( script: """
52 #!/usr/bin/env bash
53 set -eu -o pipefail
pierventre4a959602020-11-02 14:46:19 +010054
Carmelo Cascone108ca5b2021-06-08 13:56:36 -070055 # checked out in a subdir so the log can be in WORKSPACE
56 cd "$GERRIT_PROJECT"
pierventre4a959602020-11-02 14:46:19 +010057
Carmelo Cascone108ca5b2021-06-08 13:56:36 -070058 # set registry/repository variables
59 export DOCKER_REGISTRY="$dockerRegistry/"
60 export DOCKER_REPOSITORY="$dockerRepo/"
pierventre4a959602020-11-02 14:46:19 +010061
Carmelo Cascone108ca5b2021-06-08 13:56:36 -070062 # Builds having a build date
63 if [ ! -z "$buildDate" ]; then
64 export DOCKER_TAG_BUILD_DATE="-$current_date"
65 fi
pierventre9692bbf2020-11-12 14:34:31 +010066
Carmelo Cascone108ca5b2021-06-08 13:56:36 -070067 # Builds having the profiler enabled
68 if [ ! -z "$PROFILER" ]; then
69 export DOCKER_TAG_PROFILER="-profiler"
70 fi
pierventre10be3042021-05-05 18:43:24 +020071
Carmelo Cascone108ca5b2021-06-08 13:56:36 -070072 # Build w/extraEnvironmentVars
73 echo "Building image with following vars $extraEnvironmentVars"
74 $extraEnvironmentVars make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
75 """)
76 }
pierventre4a959602020-11-02 14:46:19 +010077 }
78 }
79 }
80 }
81 }
82
83 stage('push'){
84 steps {
85 script {
86 withDockerRegistry(credentialsId: 'aether-internal-registry', url: "https://${params.dockerRegistry}") {
87 sh( script:"""
88 #!/usr/bin/env bash
89 set -eu -o pipefail
90
91 # checked out in a subdir so the log can be in WORKSPACE
92 cd "$GERRIT_PROJECT"
93
94 # set registry/repository variables
95 export DOCKER_REGISTRY="$dockerRegistry/"
96 export DOCKER_REPOSITORY="$dockerRepo/"
97
pierventre10be3042021-05-05 18:43:24 +020098 # Builds having a build date
99 if [ ! -z "$buildDate" ]; then
100 export DOCKER_TAG_BUILD_DATE="-$current_date"
101 fi
102
103 # Builds having the profiler enabled
104 if [ ! -z "$PROFILER" ]; then
105 export DOCKER_TAG_PROFILER="-profiler"
106 fi
pierventre9692bbf2020-11-12 14:34:31 +0100107
pierventre4a959602020-11-02 14:46:19 +0100108 # Push w/extraEnvironmentVars
109 echo "Pushing image with following vars $extraEnvironmentVars"
110 $extraEnvironmentVars make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
111 """)
112 }
113 }
114 }
115 }
116 }
117
118 post {
119 always {
120 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
121 deleteDir()
122 }
123 failure {
124 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
125 }
126 }
127}