Skip to content

Commit e0be3fb

Browse files
authored
Add docker image build in Jenkinsfile (#1351)
* Add docker image build in Jenkinsfile * Not check branch when build image
1 parent f7fdb7d commit e0be3fb

1 file changed

Lines changed: 50 additions & 6 deletions

File tree

Jenkinsfile

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
def artifact="deployments/launcher/target/*-skinny.tar.gz"
2+
def img_build_hook = null
3+
14
pipeline {
25
agent { label 'maven' }
36
stages {
@@ -7,24 +10,65 @@ pipeline {
710
}
811
}
912
stage('Build') {
13+
steps {
14+
sh 'mvn -B -V clean verify'
15+
}
16+
}
17+
stage('Function Test') {
1018
when {
1119
expression { env.CHANGE_ID != null } // Pull request
1220
}
1321
steps {
14-
sh 'mvn -B -V clean verify -Prun-its -Pci'
22+
sh 'mvn -B -V verify -Prun-its -Pci'
1523
}
1624
}
1725
stage('Deploy') {
1826
when { branch 'master' }
1927
steps {
2028
echo "Deploy"
21-
sh 'mvn help:effective-settings -B -V clean deploy -e -s ~/sonatype/settings.xml'
29+
sh 'mvn help:effective-settings -B -V deploy -e -s ~/sonatype/settings.xml'
2230
}
2331
}
24-
}
25-
post {
26-
success {
27-
archiveArtifacts artifacts: 'deployments/launcher/target/*-skinny.tar.gz', fingerprint: true
32+
stage('Archive') {
33+
steps {
34+
echo "Archive"
35+
archiveArtifacts artifacts: "$artifact", fingerprint: true
36+
}
37+
}
38+
stage('Check Image Build Hook') {
39+
when {
40+
expression { env.IMG_BUILD_HOOKS != null }
41+
}
42+
steps {
43+
echo "Check Image Build Hook"
44+
script {
45+
def jsonObj = readJSON text: env.IMG_BUILD_HOOKS
46+
if (env.GIT_URL in jsonObj) {
47+
img_build_hook = jsonObj[env.GIT_URL]
48+
}
49+
}
50+
}
51+
}
52+
stage('Build & Push Image') {
53+
when {
54+
allOf {
55+
expression { img_build_hook != null }
56+
expression { env.CHANGE_ID == null } // Not pull request
57+
}
58+
}
59+
steps {
60+
script {
61+
echo "Build docker image"
62+
def artifact_file = sh(script: "ls $artifact", returnStdout: true)?.trim()
63+
def tarball_url = "${BUILD_URL}artifact/$artifact_file"
64+
sh """cat <<EOF > payload_file.yaml
65+
env:
66+
- name: "tarball_url"
67+
value: "${tarball_url}"
68+
EOF"""
69+
sh "curl -H 'Content-Type: application/yaml' --data-binary @payload_file.yaml -k -X POST ${img_build_hook}"
70+
}
71+
}
2872
}
2973
}
3074
}

0 commit comments

Comments
 (0)