blob: 89eef34e51f8979e4fc18e7cd1f907b646668a27 [file] [log] [blame]
Zack Williamse16a9bd2019-03-21 23:02:24 -07001/* docker-publish pipeline */
2pipeline {
3
4 /* no label, executor is determined by JJB */
5 agent {
6 label "${params.executorNode}"
7 }
8 stages {
9
10 stage('checkout') {
11 steps {
12 checkout([
13 $class: 'GitSCM',
14 userRemoteConfigs: [[
15 url: "${params.gitUrl}",
16 name: "${params.GERRIT_PATCHSET_REVISION}",
17 ]],
18 extensions: [
19 [$class: 'WipeWorkspace'],
20 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.GERRIT_PROJECT}"],
21 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
22 ],
23 ])
24 script {
25 def git_tags={ shell "git tag -l --points-at HEAD" }
26 }
27 }
28 }
29
30 stage('build'){
31 steps {
32 sh """
33 #!/usr/bin/env bash
34 set -eu -o pipefail
35
36 # checked out in a subdir so the log can be in WORKSPACE
37 cd "$GERRIT_PROJECT"
38
39 export DOCKER_REPOSITORY="$dockerRepo/"
40
41 # Build w/branch
42 echo "Building image with branch"
43 make DOCKER_TAG="$GERRIT_BRANCH" docker-build 2>&1 | tee > "$WORKSPACE/docker-build.log"
44
45 # Build w/tags if they exist
46 if [ -n "$git_tags" ]
47 then
48 for tag in $git_tags
49 do
50 echo "Building image with tag (should reuse cached layers)"
51 make DOCKER_TAG="$tag" docker-build
52 done
53 fi
54 """
55 }
56 }
57
58 stage('push'){
59 steps {
60 script {
61 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
62 sh """
63 #!/usr/bin/env bash
64 set -eu -o pipefail
65
66 # checked out in a subdir so the log can be in WORKSPACE
67 cd "$GERRIT_PROJECT"
68
69 export DOCKER_REPOSITORY="$dockerRepo/"
70
71 # Push w/branch
72 echo "Pushing image with branch"
73 make DOCKER_TAG="$GERRIT_BRANCH" docker-push 2>&1 | tee > "$WORKSPACE/docker-push.log"
74
75 # Push w/tags if they exist
76 if [ -n "$git_tags" ]
77 then
78 for tag in $git_tags
79 do
80 echo "Pushing image with tag (should reuse cached layers)"
81 make DOCKER_TAG="$tag" docker-push
82 done
83 fi
84 """
85 }
86 }
87 }
88 }
89 }
90
91 post {
92 always {
93 archiveArtifacts artifacts: 'docker-build.log', fingerprint: true
94 deleteDir()
95 }
96 }
97}