-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJenkinsfile
More file actions
94 lines (87 loc) · 3.1 KB
/
Jenkinsfile
File metadata and controls
94 lines (87 loc) · 3.1 KB
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
def SLACK_URL = "https://hooks.slack.com/services/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"
def icon = ":heavy_check_mark:"
/*
nativerl pipeline
The pipeline is made up of following steps
1. Git clone and setup
2. Build and s3 push
4. Optionally deploy to production and test
*/
/*
Build a docker image
*/
def buildNativerl(image_name) {
echo "Building the nativerl Docker Image for branch ${env.BRANCH_NAME}"
sh """
set +x
docker image ls | grep nativerl | awk '{print \$3}' | xargs -I {} docker rmi {} -f
docker build -t ${image_name} -f ${WORKSPACE}/Dockerfile ${WORKSPACE}
"""
sh "docker run --mount \"src=${WORKSPACE}/,target=/app,type=bind\" nativerl mvn clean install -Djavacpp.platform=linux-x86_64"
sh "aws s3 cp ${WORKSPACE}/nativerl/target/nativerl-1.8.1-SNAPSHOT-bin.zip s3://${env.BRANCH_NAME}-training-static-files.pathmind.com/nativerl/1_8_1/nativerl-1.8.1-SNAPSHOT-bin.zip"
}
/*
This is the main pipeline section with the stages of the CI/CD
*/
pipeline {
options {
// Build auto timeout
timeout(time: 60, unit: 'MINUTES')
disableConcurrentBuilds()
}
// Some global default variables
environment {
IMAGE_NAME = 'nativerl'
DEPLOY_PROD = false
}
//all is built and run from the master
agent { node { label 'master' } }
// Pipeline stages
stages {
stage('Git clone and setup') {
when {
anyOf {
environment name: 'GIT_BRANCH', value: 'dev'
environment name: 'GIT_BRANCH', value: 'test'
environment name: 'GIT_BRANCH', value: 'staging'
environment name: 'GIT_BRANCH', value: 'prod'
}
}
steps {
echo "Notifying slack"
sh "set +x; curl -X POST -H 'Content-type: application/json' --data '{\"text\":\":building_construction: Starting Jenkins Job\nBranch: ${env.BRANCH_NAME}\nUrl: ${env.RUN_DISPLAY_URL}\"}' ${SLACK_URL}"
echo "Check out code"
checkout scm
}
}
stage('Build Docker Images') {
parallel {
stage('Build nativerl image') {
when {
anyOf {
environment name: 'GIT_BRANCH', value: 'dev'
environment name: 'GIT_BRANCH', value: 'test'
environment name: 'GIT_BRANCH', value: 'staging'
environment name: 'GIT_BRANCH', value: 'prod'
}
}
steps {
buildNativerl("${IMAGE_NAME}")
}
}
}
}
}
post {
always {
echo 'Notifying Slack'
script {
if (currentBuild.result != "SUCCESS") {
icon = ":x:"
}
}
echo "Notifying slack"
sh "set +x; curl -X POST -H 'Content-type: application/json' --data '{\"text\":\"${icon} Jenkins Job Finished\nBranch: ${env.BRANCH_NAME}\nUrl: ${env.RUN_DISPLAY_URL}\nStatus: ${currentBuild.result}\"}' ${SLACK_URL}"
}
}
}