blob: 8b38bd49b6d5869a7b9b3e00ded88e984ac51b05 [file] [log] [blame]
pierventref41b90c2020-07-15 16:26:02 +02001// Copyright 2017-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/* docker-publish pipeline */
16pipeline {
17
18 /* executor is determined by JJB */
19 agent {
20 label "${params.buildNode}"
21 }
22 stages {
23
24 stage('checkout') {
25 steps {
26 checkout([
27 $class: 'GitSCM',
pierventre07ef37d2020-07-23 12:23:17 +020028 userRemoteConfigs: [[ url: "${params.gitUrl}", credentialsId: 'onos-jenkins-ssh', refspec: "${params.gitRefSpec}"]],
pierventref41b90c2020-07-15 16:26:02 +020029 branches: [[ name: "${params.gitRef}", ]],
30 extensions: [
31 [$class: 'WipeWorkspace'],
32 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.projectName}"],
33 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
34 [$class: 'SubmoduleOption', recursiveSubmodules: true],
35 ],
36 ])
37 script {
38 git_tags = sh(script:"cd $projectName; git tag -l --points-at HEAD", returnStdout: true).trim()
39 }
40 }
41 }
42
43 stage('build'){
44 steps {
pierventre65d85a22020-07-21 20:30:20 +020045 script {
pierventref0183f92020-10-05 22:40:49 +020046 sshagent(credentials: ['github-onf-bot-ssh-key', 'github-omec-project-ssh-key']) {
pierventre63d7e2c2020-07-30 17:49:02 +020047 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
48 sh( script: """
49 #!/usr/bin/env bash
50 set -eu -o pipefail
pierventref41b90c2020-07-15 16:26:02 +020051
pierventre63d7e2c2020-07-30 17:49:02 +020052 # checked out in a subdir so the log can be in WORKSPACE
53 cd "$projectName"
pierventref41b90c2020-07-15 16:26:02 +020054
pierventre63d7e2c2020-07-30 17:49:02 +020055 # set registry/repository variables
56 export DOCKER_REGISTRY="$dockerRegistry/"
57 export DOCKER_REPOSITORY="$dockerRepo/"
pierventref41b90c2020-07-15 16:26:02 +020058
pierventre63d7e2c2020-07-30 17:49:02 +020059 # Build w/branch
60 echo "Building image with branch"
61 $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
pierventref41b90c2020-07-15 16:26:02 +020062
pierventre63d7e2c2020-07-30 17:49:02 +020063 # Build w/tags if they exist
64 if [ -n "$git_tags" ]
65 echo "Tags found in git, building:"
66 echo "$git_tags"
pierventref41b90c2020-07-15 16:26:02 +020067
pierventre63d7e2c2020-07-30 17:49:02 +020068 then
69 for tag in $git_tags
70 do
71 # remove leading 'v' on funky golang tags
72 clean_tag=\$(echo \$tag | sed 's/^v//g')
73 echo "Building image with tag: \$clean_tag (should reuse cached layers)"
74 $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-build
75 done
76 fi
77 """)
78 }
pierventre65d85a22020-07-21 20:30:20 +020079 }
80 }
81 }
pierventref41b90c2020-07-15 16:26:02 +020082 }
83 }
84
85 stage('push'){
86 steps {
87 script {
pierventre0ac63812020-07-27 11:59:49 +020088 withDockerRegistry(credentialsId: 'aether-internal-registry', url: "https://${params.dockerRegistry}") {
pierventref41b90c2020-07-15 16:26:02 +020089 sh( script:"""
90 #!/usr/bin/env bash
91 set -eu -o pipefail
92
93 # checked out in a subdir so the log can be in WORKSPACE
94 cd "$projectName"
95
96 # set registry/repository variables
pierventre0ac63812020-07-27 11:59:49 +020097 export DOCKER_REGISTRY="$dockerRegistry/"
pierventref41b90c2020-07-15 16:26:02 +020098 export DOCKER_REPOSITORY="$dockerRepo/"
99
100 # Push w/branch
101 echo "Pushing image with branch"
102 $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
103
104 # Push w/tags if they exist
105 if [ -n "$git_tags" ]
106 echo "Tags found in git, pushing:"
107 echo "$git_tags"
108 then
109 for tag in $git_tags
110 do
111 # remove leading 'v' on funky golang tags
112 clean_tag=\$(echo \$tag | sed 's/^v//g')
113 echo "Pushing image with tag: \$clean_tag (should reuse cached layers)"
114 $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-push
115 done
116 fi
117 """)
118 }
119 }
120 }
121 }
122 }
123
124 post {
125 always {
126 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
127 deleteDir()
128 }
129 failure {
130 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
131 }
132 }
133}