forked from bbc/simorgh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
110 lines (108 loc) · 2.96 KB
/
Jenkinsfile
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env groovy
def dockerRegistry = "329802642264.dkr.ecr.eu-west-1.amazonaws.com"
def nodeImageVersion = "0.0.5"
def nodeImage = "${dockerRegistry}/bbc-news/node-8-lts:${nodeImageVersion}"
def nodeName
def stageName = ""
def getCommitInfo = {
infraGitCommitAuthor = sh(returnStdout: true, script: "git --no-pager show -s --format='%an' ${GIT_COMMIT}").trim()
appGitCommit = sh(returnStdout: true, script: "cd ${APP_DIRECTORY}; git rev-parse HEAD")
appGitCommitAuthor = sh(returnStdout: true, script: "cd ${APP_DIRECTORY}; git --no-pager show -s --format='%an' ${appGitCommit}").trim()
appGitCommitMessage = sh(returnStdout: true, script: "cd ${APP_DIRECTORY}; git log -1 --pretty=%B").trim()
}
pipeline {
agent any
options {
timeout(time: 60, unit: 'MINUTES')
timestamps ()
}
environment {
APP_DIRECTORY = "app"
CI = true
}
stages {
stage('Checkout application repo') {
when {
expression { env.BRANCH_NAME != 'latest' }
}
agent {
docker {
image "${nodeImage}"
args '-u root -v /etc/pki:/certs'
}
}
steps {
sh "rm -rf ${env.APP_DIRECTORY}"
checkout([
$class: 'GitSCM',
branches: [[name: "*/${env.BRANCH_NAME}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: "${env.APP_DIRECTORY}"
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'github',
name: "origin/${env.BRANCH_NAME}",
url: 'https://github.com/bbc/simorgh.git'
]]
])
script {
getCommitInfo()
nodeName = "${env.node_name}".toString()
}
}
post {
always {
script {
stageName = env.STAGE_NAME
}
}
}
}
stage ('Run application tests') {
when {
expression { env.BRANCH_NAME != 'latest' }
}
agent {
docker {
image "${nodeImage}"
label nodeName
args '-u root -v /etc/pki:/certs'
}
}
steps {
sh 'make install'
sh 'make developmentTests'
sh 'make installProd'
sh 'make productionTests'
}
post {
always {
script {
stageName = env.STAGE_NAME
}
}
}
}
stage ('Run Pipeline') {
when {
expression { env.BRANCH_NAME == 'latest' }
}
agent any
steps {
build(
job: 'simorgh-infrastructure/latest',
parameters: [
[$class: 'StringParameterValue', name: 'BRANCH', value: env.BRANCH_NAME],
[$class: 'StringParameterValue', name: 'APPLICATION_BRANCH', value: env.BRANCH_NAME],
[$class: 'StringParameterValue', name: 'ENVIRONMENT', value: 'live'],
],
propagate: true,
wait: true
)
}
}
}
}