-
Notifications
You must be signed in to change notification settings - Fork 18
/
Jenkinsfile
80 lines (73 loc) · 2.65 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
def Deployer, Github
node {
checkout(scm)
def version = sh(script: 'git log -n 1 --pretty=format:\'%h\'', returnStdout: true).trim()
// Load library from currently checked out code. Also loads global vars
// in addition to the Deployer class assigned here.
def salemove = library(identifier: "pipeline-lib@${version}", retriever: legacySCM(scm)).com.salemove
Deployer = salemove.Deployer
Github = salemove.deploy.Github
}
def projectName = 'deploy-pipeline-test'
def actualResponse = { envName, domainName ->
def response
container('deployer-container') {
response = sh(
script: "curl -H 'Host: ${projectName}.${domainName}' gateway.${domainName}",
returnStdout: true
).trim()
}
response
}
def expectedBuildValue = { version -> version }
def expectedTemplateValue = { version, envName -> "${envName}-${version}" }
def expectedResponse = { version, envName ->
"BUILD_VALUE=${expectedBuildValue(version)}, TEMPLATE_VALUE=${expectedTemplateValue(version, envName)}"
}
properties(deployer.wrapProperties())
withResultReporting(slackChannel: '#tm-is') {
inDockerAgent(deployer.wrapPodTemplate()) {
def image, version
stage('Build') {
checkout(scm)
version = sh(script: 'git log -n 1 --pretty=format:\'%h\'', returnStdout: true).trim()
image = docker.build(projectName, "--build-arg 'BUILD_VALUE=${version}' test")
}
deployer.deployOnCommentTrigger(
image: image,
kubernetesNamespace: 'default',
kubernetesDeployment: projectName,
// inAcceptance is deprecated, but is left here to test backwards
// compatibility
inAcceptance: {
def response = actualResponse('acceptance', 'at.samo.io')
def expectation = expectedResponse(version, 'acceptance')
if (response != expectation) {
error("Expected response to be \"${expectation}\", but was \"${response}\"")
}
},
automaticChecksFor: { env ->
env['runInKube'](
command: './test.sh',
additionalArgs: "--env='BUILD_VALUE=${expectedBuildValue(version)}'" +
" --env='TEMPLATE_VALUE=${expectedTemplateValue(version, env.name)}'"
)
},
checklistFor: { env ->
[[
name: 'OK?',
description: "Are you feeling good about this change in ${env.name}? https://app.${env.domainName}"
]]
}
)
def isPRBuild = !!env.CHANGE_ID
if (isPRBuild && !Deployer.isDeploy(this)) {
pullRequest.createStatus(
status: 'success',
context: Github.deployStatusContext,
description: 'PRs in this project don\'t have to necessarily be deployed',
targetUrl: BUILD_URL
)
}
}
}