pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 1 | // 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 Cascone | 7980549 | 2022-02-04 17:27:21 -0800 | [diff] [blame] | 15 | def dockerRegistry = params.dockerRegistry ? "${params.dockerRegistry}/" : "" |
| 16 | |
Charles Chan | f73d240 | 2022-02-09 22:38:19 -0800 | [diff] [blame] | 17 | /* sdfabric-onos-publish pipeline.*/ |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 18 | pipeline { |
| 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 { |
pierventre | 9692bbf | 2020-11-12 14:34:31 +0100 | [diff] [blame] | 42 | current_date = sh(returnStdout: true, script: 'date +%Y-%m-%d').trim() |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 43 | } |
| 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 Cascone | 7980549 | 2022-02-04 17:27:21 -0800 | [diff] [blame] | 52 | // 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 |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 57 | |
Carmelo Cascone | 7980549 | 2022-02-04 17:27:21 -0800 | [diff] [blame] | 58 | # checked out in a subdir so the log can be in WORKSPACE |
| 59 | cd "$GERRIT_PROJECT" |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 60 | |
Carmelo Cascone | 7980549 | 2022-02-04 17:27:21 -0800 | [diff] [blame] | 61 | # set registry/repository variables |
| 62 | export DOCKER_REGISTRY="$dockerRegistry" |
| 63 | export DOCKER_REPOSITORY="$dockerRepo" |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 64 | |
Carmelo Cascone | 7980549 | 2022-02-04 17:27:21 -0800 | [diff] [blame] | 65 | # Builds having a build date |
| 66 | if [ ! -z "$buildDate" ]; then |
| 67 | export DOCKER_TAG_BUILD_DATE="-$current_date" |
| 68 | fi |
pierventre | 9692bbf | 2020-11-12 14:34:31 +0100 | [diff] [blame] | 69 | |
Carmelo Cascone | 7980549 | 2022-02-04 17:27:21 -0800 | [diff] [blame] | 70 | # Builds having the profiler enabled |
| 71 | if [ ! -z "$PROFILER" ]; then |
| 72 | export DOCKER_TAG_PROFILER="-profiler" |
| 73 | fi |
pierventre | 10be304 | 2021-05-05 18:43:24 +0200 | [diff] [blame] | 74 | |
Carmelo Cascone | 7980549 | 2022-02-04 17:27:21 -0800 | [diff] [blame] | 75 | # 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 | } |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | stage('push'){ |
| 87 | steps { |
| 88 | script { |
Charles Chan | 89e04a4 | 2022-02-03 22:55:19 -0800 | [diff] [blame] | 89 | withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) { |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 90 | 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 Cascone | 7980549 | 2022-02-04 17:27:21 -0800 | [diff] [blame] | 98 | export DOCKER_REGISTRY="$dockerRegistry" |
Charles Chan | 89e04a4 | 2022-02-03 22:55:19 -0800 | [diff] [blame] | 99 | export DOCKER_REPOSITORY="$dockerRepo" |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 100 | |
pierventre | 10be304 | 2021-05-05 18:43:24 +0200 | [diff] [blame] | 101 | # 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 |
pierventre | 9692bbf | 2020-11-12 14:34:31 +0100 | [diff] [blame] | 110 | |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 111 | # 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 | } |