blob: e9f05a39b4274670290e987e752ed7bcd846a96c [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}",
Zack Williams38126df2019-03-21 23:02:24 -070016 name: "${params.gitRef}",
Zack Williamse16a9bd2019-03-21 23:02:24 -070017 ]],
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 {
Zack Williams38126df2019-03-21 23:02:24 -070025 git_tags = sh(script:"cd $GERRIT_PROJECT; git tag -l --points-at HEAD", returnStdout: true).trim()
Zack Williamse16a9bd2019-03-21 23:02:24 -070026 }
27 }
28 }
29
30 stage('build'){
31 steps {
Zack Williams38126df2019-03-21 23:02:24 -070032 sh( script: """
Zack Williamse16a9bd2019-03-21 23:02:24 -070033 #!/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
Zack Williams38126df2019-03-21 23:02:24 -070039 # set registry/repository variables
40 export DOCKER_REGISTRY="$dockerRegistry"
Zack Williamse16a9bd2019-03-21 23:02:24 -070041 export DOCKER_REPOSITORY="$dockerRepo/"
42
43 # Build w/branch
44 echo "Building image with branch"
Zack Williams38126df2019-03-21 23:02:24 -070045 make DOCKER_TAG="$GERRIT_BRANCH" docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
Zack Williamse16a9bd2019-03-21 23:02:24 -070046
47 # Build w/tags if they exist
48 if [ -n "$git_tags" ]
Zack Williams38126df2019-03-21 23:02:24 -070049 echo "Tags found in git, building:"
50 echo "$git_tags"
51
Zack Williamse16a9bd2019-03-21 23:02:24 -070052 then
53 for tag in $git_tags
54 do
Zack Williams38126df2019-03-21 23:02:24 -070055 echo "Building image with tag: \$tag (should reuse cached layers)"
56 make DOCKER_TAG="\$tag" docker-build
Zack Williamse16a9bd2019-03-21 23:02:24 -070057 done
58 fi
Zack Williams38126df2019-03-21 23:02:24 -070059 """)
Zack Williamse16a9bd2019-03-21 23:02:24 -070060 }
61 }
62
63 stage('push'){
64 steps {
65 script {
66 withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
Zack Williams38126df2019-03-21 23:02:24 -070067 sh( script:"""
Zack Williamse16a9bd2019-03-21 23:02:24 -070068 #!/usr/bin/env bash
69 set -eu -o pipefail
70
71 # checked out in a subdir so the log can be in WORKSPACE
72 cd "$GERRIT_PROJECT"
73
Zack Williams38126df2019-03-21 23:02:24 -070074 # set registry/repository variables
75 export DOCKER_REGISTRY="$dockerRegistry"
Zack Williamse16a9bd2019-03-21 23:02:24 -070076 export DOCKER_REPOSITORY="$dockerRepo/"
77
78 # Push w/branch
79 echo "Pushing image with branch"
Zack Williams38126df2019-03-21 23:02:24 -070080 make DOCKER_TAG="$GERRIT_BRANCH" docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
Zack Williamse16a9bd2019-03-21 23:02:24 -070081
82 # Push w/tags if they exist
83 if [ -n "$git_tags" ]
Zack Williams38126df2019-03-21 23:02:24 -070084 echo "Tags found in git, pushing:"
85 echo "$git_tags"
Zack Williamse16a9bd2019-03-21 23:02:24 -070086 then
87 for tag in $git_tags
88 do
Zack Williams38126df2019-03-21 23:02:24 -070089 echo "Pushing image with tag: \$tag (should reuse cached layers)"
90 make DOCKER_TAG="\$tag" docker-push
Zack Williamse16a9bd2019-03-21 23:02:24 -070091 done
92 fi
Zack Williams38126df2019-03-21 23:02:24 -070093 """)
Zack Williamse16a9bd2019-03-21 23:02:24 -070094 }
95 }
96 }
97 }
98 }
99
100 post {
101 always {
Zack Williams38126df2019-03-21 23:02:24 -0700102 archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
Zack Williamse16a9bd2019-03-21 23:02:24 -0700103 deleteDir()
104 }
105 }
106}