blob: dce23f1085af1d9daa066b90d18f338208aafa17 [file] [log] [blame]
Zack Williams3bf60d52019-06-07 12:56:10 -07001// 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
Zack Williamse16a9bd2019-03-21 23:02:24 -070015/* docker-publish pipeline */
16pipeline {
17
18 /* no label, executor is determined by JJB */
19 agent {
20 label "${params.executorNode}"
21 }
22 stages {
23
24 stage('checkout') {
25 steps {
26 checkout([
27 $class: 'GitSCM',
28 userRemoteConfigs: [[
29 url: "${params.gitUrl}",
Zack Williams38126df2019-03-21 23:02:24 -070030 name: "${params.gitRef}",
Zack Williamse16a9bd2019-03-21 23:02:24 -070031 ]],
32 extensions: [
33 [$class: 'WipeWorkspace'],
Zack Williams8d92d6d2019-04-16 18:12:12 -070034 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.projectName}"],
Zack Williamse16a9bd2019-03-21 23:02:24 -070035 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
36 ],
37 ])
38 script {
Zack Williams8d92d6d2019-04-16 18:12:12 -070039 git_tags = sh(script:"cd $projectName; git tag -l --points-at HEAD", returnStdout: true).trim()
Zack Williamse16a9bd2019-03-21 23:02:24 -070040 }
41 }
42 }
43
44 stage('build'){
45 steps {
Zack Williams38126df2019-03-21 23:02:24 -070046 sh( script: """
Zack Williamse16a9bd2019-03-21 23:02:24 -070047 #!/usr/bin/env bash
48 set -eu -o pipefail
49
50 # checked out in a subdir so the log can be in WORKSPACE
Zack Williams8d92d6d2019-04-16 18:12:12 -070051 cd "$projectName"
Zack Williamse16a9bd2019-03-21 23:02:24 -070052
Zack Williams38126df2019-03-21 23:02:24 -070053 # set registry/repository variables
54 export DOCKER_REGISTRY="$dockerRegistry"
Zack Williamse16a9bd2019-03-21 23:02:24 -070055 export DOCKER_REPOSITORY="$dockerRepo/"
56
57 # Build w/branch
58 echo "Building image with branch"
Zack Williams8d92d6d2019-04-16 18:12:12 -070059 make DOCKER_TAG="$branchName" docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
Zack Williamse16a9bd2019-03-21 23:02:24 -070060
61 # Build w/tags if they exist
62 if [ -n "$git_tags" ]
Zack Williams38126df2019-03-21 23:02:24 -070063 echo "Tags found in git, building:"
64 echo "$git_tags"
65
Zack Williamse16a9bd2019-03-21 23:02:24 -070066 then
67 for tag in $git_tags
68 do
Zack Williams38126df2019-03-21 23:02:24 -070069 echo "Building image with tag: \$tag (should reuse cached layers)"
70 make DOCKER_TAG="\$tag" docker-build
Zack Williamse16a9bd2019-03-21 23:02:24 -070071 done
72 fi
Zack Williams38126df2019-03-21 23:02:24 -070073 """)
Zack Williamse16a9bd2019-03-21 23:02:24 -070074 }
75 }
76
77 stage('push'){
78 steps {
79 script {
80 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
Zack Williams38126df2019-03-21 23:02:24 -070081 sh( script:"""
Zack Williamse16a9bd2019-03-21 23:02:24 -070082 #!/usr/bin/env bash
83 set -eu -o pipefail
84
85 # checked out in a subdir so the log can be in WORKSPACE
Zack Williams8d92d6d2019-04-16 18:12:12 -070086 cd "$projectName"
Zack Williamse16a9bd2019-03-21 23:02:24 -070087
Zack Williams38126df2019-03-21 23:02:24 -070088 # set registry/repository variables
89 export DOCKER_REGISTRY="$dockerRegistry"
Zack Williamse16a9bd2019-03-21 23:02:24 -070090 export DOCKER_REPOSITORY="$dockerRepo/"
91
92 # Push w/branch
93 echo "Pushing image with branch"
Zack Williams8d92d6d2019-04-16 18:12:12 -070094 make DOCKER_TAG="$branchName" docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
Zack Williamse16a9bd2019-03-21 23:02:24 -070095
96 # Push w/tags if they exist
97 if [ -n "$git_tags" ]
Zack Williams38126df2019-03-21 23:02:24 -070098 echo "Tags found in git, pushing:"
99 echo "$git_tags"
Zack Williamse16a9bd2019-03-21 23:02:24 -0700100 then
101 for tag in $git_tags
102 do
Zack Williams38126df2019-03-21 23:02:24 -0700103 echo "Pushing image with tag: \$tag (should reuse cached layers)"
104 make DOCKER_TAG="\$tag" docker-push
Zack Williamse16a9bd2019-03-21 23:02:24 -0700105 done
106 fi
Zack Williams38126df2019-03-21 23:02:24 -0700107 """)
Zack Williamse16a9bd2019-03-21 23:02:24 -0700108 }
109 }
110 }
111 }
112 }
113
114 post {
115 always {
Zack Williams38126df2019-03-21 23:02:24 -0700116 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
Zack Williamse16a9bd2019-03-21 23:02:24 -0700117 deleteDir()
118 }
119 }
120}