blob: f0cb8c66c822bfeab67a99cef73c1664eabed546 [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 {
pierventre3b863cf2020-10-06 20:53:10 +020046 sshagent(credentials: ['github-onf-bot-ssh-key']) {
pierventred424a4e2020-10-06 14:42:27 +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
pierventred424a4e2020-10-06 14:42:27 +020052 # checked out in a subdir so the log can be in WORKSPACE
53 cd "$projectName"
pierventref41b90c2020-07-15 16:26:02 +020054
pierventred424a4e2020-10-06 14:42:27 +020055 # set registry/repository variables
56 export DOCKER_REGISTRY="$dockerRegistry/"
57 export DOCKER_REPOSITORY="$dockerRepo/"
pierventref41b90c2020-07-15 16:26:02 +020058
pierventred424a4e2020-10-06 14:42:27 +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
pierventred424a4e2020-10-06 14:42:27 +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
pierventred424a4e2020-10-06 14:42:27 +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 """)
pierventre65d85a22020-07-21 20:30:20 +020078 }
79 }
80 }
pierventref41b90c2020-07-15 16:26:02 +020081 }
82 }
83
84 stage('push'){
85 steps {
86 script {
pierventre0ac63812020-07-27 11:59:49 +020087 withDockerRegistry(credentialsId: 'aether-internal-registry', url: "https://${params.dockerRegistry}") {
pierventref41b90c2020-07-15 16:26:02 +020088 sh( script:"""
89 #!/usr/bin/env bash
90 set -eu -o pipefail
91
92 # checked out in a subdir so the log can be in WORKSPACE
93 cd "$projectName"
94
95 # set registry/repository variables
pierventre0ac63812020-07-27 11:59:49 +020096 export DOCKER_REGISTRY="$dockerRegistry/"
pierventref41b90c2020-07-15 16:26:02 +020097 export DOCKER_REPOSITORY="$dockerRepo/"
98
99 # Push w/branch
100 echo "Pushing image with branch"
101 $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
102
103 # Push w/tags if they exist
104 if [ -n "$git_tags" ]
105 echo "Tags found in git, pushing:"
106 echo "$git_tags"
107 then
108 for tag in $git_tags
109 do
110 # remove leading 'v' on funky golang tags
111 clean_tag=\$(echo \$tag | sed 's/^v//g')
112 echo "Pushing image with tag: \$clean_tag (should reuse cached layers)"
113 $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-push
114 done
115 fi
116 """)
117 }
118 }
119 }
120 }
121 }
122
123 post {
124 always {
125 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
126 deleteDir()
127 }
128 failure {
129 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
130 }
131 }
132}