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']) { |
| 50 | sh( script: """ |
| 51 | #!/usr/bin/env bash |
| 52 | set -eu -o pipefail |
| 53 | |
| 54 | # checked out in a subdir so the log can be in WORKSPACE |
| 55 | cd "$GERRIT_PROJECT" |
| 56 | |
| 57 | # set registry/repository variables |
| 58 | export DOCKER_REGISTRY="$dockerRegistry/" |
| 59 | export DOCKER_REPOSITORY="$dockerRepo/" |
| 60 | |
pierventre | 9692bbf | 2020-11-12 14:34:31 +0100 | [diff] [blame] | 61 | # Builds having a build date |
| 62 | if [ ! -z "$buildDate" ]; then |
| 63 | export DOCKER_TAG_BUILD_DATE="-$current_date" |
| 64 | fi |
| 65 | |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 66 | # Build w/extraEnvironmentVars |
| 67 | echo "Building image with following vars $extraEnvironmentVars" |
| 68 | $extraEnvironmentVars make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log" |
| 69 | """) |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | stage('push'){ |
| 77 | steps { |
| 78 | script { |
| 79 | withDockerRegistry(credentialsId: 'aether-internal-registry', url: "https://${params.dockerRegistry}") { |
| 80 | sh( script:""" |
| 81 | #!/usr/bin/env bash |
| 82 | set -eu -o pipefail |
| 83 | |
| 84 | # checked out in a subdir so the log can be in WORKSPACE |
| 85 | cd "$GERRIT_PROJECT" |
| 86 | |
| 87 | # set registry/repository variables |
| 88 | export DOCKER_REGISTRY="$dockerRegistry/" |
| 89 | export DOCKER_REPOSITORY="$dockerRepo/" |
| 90 | |
pierventre | 9692bbf | 2020-11-12 14:34:31 +0100 | [diff] [blame] | 91 | # Builds having a build date |
| 92 | if [ ! -z "$buildDate" ]; then |
| 93 | export DOCKER_TAG_BUILD_DATE="-$current_date" |
| 94 | fi |
| 95 | |
pierventre | 4a95960 | 2020-11-02 14:46:19 +0100 | [diff] [blame] | 96 | # Push w/extraEnvironmentVars |
| 97 | echo "Pushing image with following vars $extraEnvironmentVars" |
| 98 | $extraEnvironmentVars make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log" |
| 99 | """) |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | post { |
| 107 | always { |
| 108 | archiveArtifacts artifacts: 'docker-*.log', fingerprint: true |
| 109 | deleteDir() |
| 110 | } |
| 111 | failure { |
| 112 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false]) |
| 113 | } |
| 114 | } |
| 115 | } |