blob: 8891fce405a9f3d40a97c3d0054f7a76307e776f [file] [log] [blame]
// Copyright 2020-present Open Networking Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/* tost-onos-publish pipeline.*/
pipeline {
/* executor is determined by JJB */
agent {
label "${params.buildNode}"
}
/* lighweight version of the docker-publish pipeline. */
stages {
stage('checkout') {
steps {
checkout([
$class: 'GitSCM',
userRemoteConfigs: [[ url: "${params.gitUrl}", credentialsId: 'onos-jenkins-ssh', refspec: "$GERRIT_REFSPEC"]],
branches: [[ name: "$GERRIT_PATCHSET_REVISION", ]],
extensions: [
[$class: 'WipeWorkspace'],
[$class: 'RelativeTargetDirectory', relativeTargetDir: "$GERRIT_PROJECT"],
[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
[$class: 'SubmoduleOption', recursiveSubmodules: true],
],
])
script {
current_date = sh(returnStdout: true, script: 'date +%Y-%m-%d').trim()
}
}
}
stage('build'){
steps {
script {
sshagent(credentials: ['github-onf-bot-ssh-key']) {
withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
sh( script: """
#!/usr/bin/env bash
set -eu -o pipefail
# checked out in a subdir so the log can be in WORKSPACE
cd "$GERRIT_PROJECT"
# set registry/repository variables
export DOCKER_REGISTRY="$dockerRegistry/"
export DOCKER_REPOSITORY="$dockerRepo"
# Builds having a build date
if [ ! -z "$buildDate" ]; then
export DOCKER_TAG_BUILD_DATE="-$current_date"
fi
# Builds having the profiler enabled
if [ ! -z "$PROFILER" ]; then
export DOCKER_TAG_PROFILER="-profiler"
fi
# Build w/extraEnvironmentVars
echo "Building image with following vars $extraEnvironmentVars"
$extraEnvironmentVars make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
""")
}
}
}
}
}
stage('push'){
steps {
script {
withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
sh( script:"""
#!/usr/bin/env bash
set -eu -o pipefail
# checked out in a subdir so the log can be in WORKSPACE
cd "$GERRIT_PROJECT"
# set registry/repository variables
export DOCKER_REGISTRY="$dockerRegistry/"
export DOCKER_REPOSITORY="$dockerRepo"
# Builds having a build date
if [ ! -z "$buildDate" ]; then
export DOCKER_TAG_BUILD_DATE="-$current_date"
fi
# Builds having the profiler enabled
if [ ! -z "$PROFILER" ]; then
export DOCKER_TAG_PROFILER="-profiler"
fi
# Push w/extraEnvironmentVars
echo "Pushing image with following vars $extraEnvironmentVars"
$extraEnvironmentVars make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
""")
}
}
}
}
}
post {
always {
archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
deleteDir()
}
failure {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
}
}
}