blob: 71e359db5acb5fe6acc7f5a8d50208f6b46f0d27 [file] [log] [blame]
Joey Armstrong6a9013e2024-02-01 17:56:57 -05001// Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
Zack Williams3bf60d52019-06-07 12:56:10 -07002//
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
Zack Williamse16a9bd2019-03-21 23:02:24 -070015/* docker-publish pipeline */
16pipeline {
17
Zack Williamsb3292082019-10-11 17:15:18 -070018 /* executor is determined by JJB */
Zack Williamse16a9bd2019-03-21 23:02:24 -070019 agent {
Zack Williamsb3292082019-10-11 17:15:18 -070020 label "${params.buildNode}"
Zack Williamse16a9bd2019-03-21 23:02:24 -070021 }
22 stages {
23
24 stage('checkout') {
25 steps {
26 checkout([
27 $class: 'GitSCM',
Zack Williams99330272019-08-21 11:33:48 -070028 userRemoteConfigs: [[ url: "${params.gitUrl}", ]],
29 branches: [[ name: "${params.gitRef}", ]],
Zack Williamse16a9bd2019-03-21 23:02:24 -070030 extensions: [
31 [$class: 'WipeWorkspace'],
Zack Williams8d92d6d2019-04-16 18:12:12 -070032 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.projectName}"],
Zack Williamse16a9bd2019-03-21 23:02:24 -070033 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
You Wang715d5fc2020-04-30 16:23:35 -070034 [$class: 'SubmoduleOption', recursiveSubmodules: true],
Zack Williamse16a9bd2019-03-21 23:02:24 -070035 ],
36 ])
37 script {
Zack Williams8d92d6d2019-04-16 18:12:12 -070038 git_tags = sh(script:"cd $projectName; git tag -l --points-at HEAD", returnStdout: true).trim()
Zack Williamse16a9bd2019-03-21 23:02:24 -070039 }
40 }
41 }
42
43 stage('build'){
44 steps {
Zack Williams38126df2019-03-21 23:02:24 -070045 sh( script: """
Zack Williamse16a9bd2019-03-21 23:02:24 -070046 #!/usr/bin/env bash
47 set -eu -o pipefail
48
49 # checked out in a subdir so the log can be in WORKSPACE
Zack Williams8d92d6d2019-04-16 18:12:12 -070050 cd "$projectName"
Zack Williamse16a9bd2019-03-21 23:02:24 -070051
Zack Williams38126df2019-03-21 23:02:24 -070052 # set registry/repository variables
53 export DOCKER_REGISTRY="$dockerRegistry"
Zack Williamse16a9bd2019-03-21 23:02:24 -070054 export DOCKER_REPOSITORY="$dockerRepo/"
55
56 # Build w/branch
57 echo "Building image with branch"
Matteo Scandolo84366122020-04-29 15:08:40 -070058 $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
Zack Williamse16a9bd2019-03-21 23:02:24 -070059
60 # Build w/tags if they exist
61 if [ -n "$git_tags" ]
Zack Williams38126df2019-03-21 23:02:24 -070062 echo "Tags found in git, building:"
63 echo "$git_tags"
64
Zack Williamse16a9bd2019-03-21 23:02:24 -070065 then
66 for tag in $git_tags
67 do
Zack Williams6e070f52019-10-04 11:08:59 -070068 # remove leading 'v' on funky golang tags
Zack Williams2763f122019-10-04 15:35:35 -070069 clean_tag=\$(echo \$tag | sed 's/^v//g')
Zack Williams6e070f52019-10-04 11:08:59 -070070 echo "Building image with tag: \$clean_tag (should reuse cached layers)"
Matteo Scandolo84366122020-04-29 15:08:40 -070071 $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-build
Zack Williamse16a9bd2019-03-21 23:02:24 -070072 done
73 fi
Zack Williams38126df2019-03-21 23:02:24 -070074 """)
Zack Williamse16a9bd2019-03-21 23:02:24 -070075 }
76 }
77
78 stage('push'){
79 steps {
80 script {
81 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
Zack Williams38126df2019-03-21 23:02:24 -070082 sh( script:"""
Zack Williamse16a9bd2019-03-21 23:02:24 -070083 #!/usr/bin/env bash
84 set -eu -o pipefail
85
86 # checked out in a subdir so the log can be in WORKSPACE
Zack Williams8d92d6d2019-04-16 18:12:12 -070087 cd "$projectName"
Zack Williamse16a9bd2019-03-21 23:02:24 -070088
Zack Williams38126df2019-03-21 23:02:24 -070089 # set registry/repository variables
90 export DOCKER_REGISTRY="$dockerRegistry"
Zack Williamse16a9bd2019-03-21 23:02:24 -070091 export DOCKER_REPOSITORY="$dockerRepo/"
92
93 # Push w/branch
94 echo "Pushing image with branch"
Matteo Scandolo84366122020-04-29 15:08:40 -070095 $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
Zack Williamse16a9bd2019-03-21 23:02:24 -070096
97 # Push w/tags if they exist
98 if [ -n "$git_tags" ]
Zack Williams38126df2019-03-21 23:02:24 -070099 echo "Tags found in git, pushing:"
100 echo "$git_tags"
Zack Williamse16a9bd2019-03-21 23:02:24 -0700101 then
102 for tag in $git_tags
103 do
Zack Williams6e070f52019-10-04 11:08:59 -0700104 # remove leading 'v' on funky golang tags
Zack Williams2763f122019-10-04 15:35:35 -0700105 clean_tag=\$(echo \$tag | sed 's/^v//g')
Zack Williams6e070f52019-10-04 11:08:59 -0700106 echo "Pushing image with tag: \$clean_tag (should reuse cached layers)"
Matteo Scandolo84366122020-04-29 15:08:40 -0700107 $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-push
Zack Williamse16a9bd2019-03-21 23:02:24 -0700108 done
109 fi
Zack Williams38126df2019-03-21 23:02:24 -0700110 """)
Zack Williamse16a9bd2019-03-21 23:02:24 -0700111 }
112 }
113 }
114 }
115 }
116
117 post {
118 always {
Zack Williams38126df2019-03-21 23:02:24 -0700119 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
Zack Williamse16a9bd2019-03-21 23:02:24 -0700120 deleteDir()
121 }
Matteo Scandolo3aba73a2019-09-27 09:03:38 -0700122 failure {
123 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
124 }
Zack Williamse16a9bd2019-03-21 23:02:24 -0700125 }
126}