This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-blog
96 lines (80 loc) · 2.94 KB
/
Jenkinsfile-blog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!groovy
@Library('lmc-jenkins2-shared-library@master')
import eu.lmc.pipeline.DockerRegistry
pipeline {
environment {
// variables
def service = "blog"
def image_name = "engineering-$service"
def registry = "dcreg.service.consul"
}
agent any
stages {
stage('Check env') {
steps {
script {
echo sh(returnStdout: true, script: 'env').trim()
}
}
}
stage('Checkout Repos') {
steps {
script {
// cleanup workspace
step([$class: 'WsCleanup'])
// checkout project
git url: 'git@github.com:almacareer/blog-content.git', branch: "$env.BRANCH_NAME", credentialsId: '12488fbd-4843-4d1a-897d-eeff450020f9'
version = "0.2.${env.BUILD_ID}"
gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
def shortCommit = gitCommit.take(11)
}
}
}
stage('Build and Tagging') {
steps {
script {
// build image
sh "docker build --rm --label gitCommit=$gitCommit -t $image_name -f Dockerfile-$service ."
sh "echo git commit $gitCommit"
sh "echo version $version"
// remove untagged images
// sh "docker images -q -f dangling=true --no-trunc $registry/$image_name | xargs --no-run-if-empty docker rmi"
}
}
}
stage('Push to DEV Registry') {
steps {
script {
// pushing
tagAndPushImageParallelIfNotExist('dev', "${image_name}", version)
}
}
}
stage('Push to PROD Registry') {
steps {
script {
// pushing
tagAndPushImageParallelIfNotExist('prod', "${image_name}", version)
}
}
}
stage('Done') {
steps {
script {
// be sure we have images
sh "docker images $registry/$image_name"
sh "printf The current docker images are:'\n'dcreg.service.consul/dev/${image_name}:$version'\n'dcreg.service.consul/prod/${image_name}:$version"
}
}
}
stage('Trigger Helm Chart Job') {
steps {
script {
def job = build job: 'blog-content--k8s', parameters: [[$class: "StringParameterValue", name: "IMAGE_VERSION", value: "$version"]]
// cleanup workspace
step([$class: 'WsCleanup'])
}
}
}
}
}