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 | |
| 15 | /* tost-onos-publish pipeline.*/ |
| 16 | pipeline { |
| 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 { |
pierventre | 9692bbf | 2020-11-12 14:34:31 +0100 | [diff] [blame] | 40 | current_date = sh(returnStdout: true, script: 'date +%Y-%m-%d').trim() |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 41 | } |
| 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 Cascone | 108ca5b | 2021-06-08 13:56:36 -0700 | [diff] [blame^] | 50 | withDockerRegistry([url: 'https://registry.opennetworking.org', credentialsId: 'onf-internal-registry']) { |
| 51 | sh( script: """ |
| 52 | #!/usr/bin/env bash |
| 53 | set -eu -o pipefail |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 54 | |
Carmelo Cascone | 108ca5b | 2021-06-08 13:56:36 -0700 | [diff] [blame^] | 55 | # checked out in a subdir so the log can be in WORKSPACE |
| 56 | cd "$GERRIT_PROJECT" |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 57 | |
Carmelo Cascone | 108ca5b | 2021-06-08 13:56:36 -0700 | [diff] [blame^] | 58 | # set registry/repository variables |
| 59 | export DOCKER_REGISTRY="$dockerRegistry/" |
| 60 | export DOCKER_REPOSITORY="$dockerRepo/" |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 61 | |
Carmelo Cascone | 108ca5b | 2021-06-08 13:56:36 -0700 | [diff] [blame^] | 62 | # Builds having a build date |
| 63 | if [ ! -z "$buildDate" ]; then |
| 64 | export DOCKER_TAG_BUILD_DATE="-$current_date" |
| 65 | fi |
pierventre | 9692bbf | 2020-11-12 14:34:31 +0100 | [diff] [blame] | 66 | |
Carmelo Cascone | 108ca5b | 2021-06-08 13:56:36 -0700 | [diff] [blame^] | 67 | # Builds having the profiler enabled |
| 68 | if [ ! -z "$PROFILER" ]; then |
| 69 | export DOCKER_TAG_PROFILER="-profiler" |
| 70 | fi |
pierventre | 10be304 | 2021-05-05 18:43:24 +0200 | [diff] [blame] | 71 | |
Carmelo Cascone | 108ca5b | 2021-06-08 13:56:36 -0700 | [diff] [blame^] | 72 | # 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 | } |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 77 | } |
| 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 | |
pierventre | 10be304 | 2021-05-05 18:43:24 +0200 | [diff] [blame] | 98 | # 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 |
pierventre | 9692bbf | 2020-11-12 14:34:31 +0100 | [diff] [blame] | 107 | |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 108 | # 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 | } |