blob: 9ec89e379a55b29dd6748b84e6fe1bea035c4bb8 [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 {
pierventre63d7e2c2020-07-30 17:49:02 +020046 withCredentials([string(credentialsId: 'onos-builder', variable: 'ONOS_BUILDER_API')]) {
47 withCredentials([string(credentialsId: '64fe2b1a-b33a-4f13-8442-ad8360434003', variable: 'OMECPROJECT_API')]) {
48 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
49 sh( script: """
50 #!/usr/bin/env bash
51 set -eu -o pipefail
pierventref41b90c2020-07-15 16:26:02 +020052
pierventre63d7e2c2020-07-30 17:49:02 +020053 # checked out in a subdir so the log can be in WORKSPACE
54 cd "$projectName"
pierventref41b90c2020-07-15 16:26:02 +020055
pierventre63d7e2c2020-07-30 17:49:02 +020056 # set registry/repository variables
57 export DOCKER_REGISTRY="$dockerRegistry/"
58 export DOCKER_REPOSITORY="$dockerRepo/"
pierventref41b90c2020-07-15 16:26:02 +020059
pierventre63d7e2c2020-07-30 17:49:02 +020060 # Build w/branch
61 echo "Building image with branch"
62 $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
pierventref41b90c2020-07-15 16:26:02 +020063
pierventre63d7e2c2020-07-30 17:49:02 +020064 # Build w/tags if they exist
65 if [ -n "$git_tags" ]
66 echo "Tags found in git, building:"
67 echo "$git_tags"
pierventref41b90c2020-07-15 16:26:02 +020068
pierventre63d7e2c2020-07-30 17:49:02 +020069 then
70 for tag in $git_tags
71 do
72 # remove leading 'v' on funky golang tags
73 clean_tag=\$(echo \$tag | sed 's/^v//g')
74 echo "Building image with tag: \$clean_tag (should reuse cached layers)"
75 $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-build
76 done
77 fi
78 """)
79 }
pierventre65d85a22020-07-21 20:30:20 +020080 }
81 }
82 }
pierventref41b90c2020-07-15 16:26:02 +020083 }
84 }
85
86 stage('push'){
87 steps {
88 script {
pierventre0ac63812020-07-27 11:59:49 +020089 withDockerRegistry(credentialsId: 'aether-internal-registry', url: "https://${params.dockerRegistry}") {
pierventref41b90c2020-07-15 16:26:02 +020090 sh( script:"""
91 #!/usr/bin/env bash
92 set -eu -o pipefail
93
94 # checked out in a subdir so the log can be in WORKSPACE
95 cd "$projectName"
96
97 # set registry/repository variables
pierventre0ac63812020-07-27 11:59:49 +020098 export DOCKER_REGISTRY="$dockerRegistry/"
pierventref41b90c2020-07-15 16:26:02 +020099 export DOCKER_REPOSITORY="$dockerRepo/"
100
101 # Push w/branch
102 echo "Pushing image with branch"
103 $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
104
105 # Push w/tags if they exist
106 if [ -n "$git_tags" ]
107 echo "Tags found in git, pushing:"
108 echo "$git_tags"
109 then
110 for tag in $git_tags
111 do
112 # remove leading 'v' on funky golang tags
113 clean_tag=\$(echo \$tag | sed 's/^v//g')
114 echo "Pushing image with tag: \$clean_tag (should reuse cached layers)"
115 $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-push
116 done
117 fi
118 """)
119 }
120 }
121 }
122 }
123 }
124
125 post {
126 always {
127 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
128 deleteDir()
129 }
130 failure {
131 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
132 }
133 }
134}