-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
57 lines (56 loc) · 1.93 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
pipeline {
agent any
environment {
registry = "808964640426.dkr.ecr.us-east-1.amazonaws.com/kontxt-smtp-emulator"
registryCredential = 'ecr-login'
}
parameters {
listGitBranches(
branchFilter: '^(?!.*master)(?!.*feature)(?!.*develop).*$',
defaultValue: '',
sortMode: 'DESCENDING_SMART',
name: 'BRANCH_SELECT',
type: 'BRANCH',
remoteURL: '[email protected]:docker/kontxt-smtp-emulator.git',
credentialsId: '518101fd-f8bc-4cd9-be3d-5ad1923621dc')
}
stages {
stage('Prepare build') {
steps {
script {
FROM_BRANCH = sh( script: '''#!/bin/bash
echo ${BRANCH_SELECT} | sed '1s|^refs/heads/||'
''',returnStdout: true)
}
git url: '[email protected]:docker/kontxt-smtp-emulator.git',
credentialsId: '518101fd-f8bc-4cd9-be3d-5ad1923621dc',
branch: "${FROM_BRANCH}"
}
}
stage('Build image'){
steps {
script {
VER = sh( script: '''#!/bin/bash
echo ${BRANCH_SELECT} | sed '1s|^refs/heads/||' | cut -d '/' -f 2
''',returnStdout: true)
sh("docker build -t kontxt-smtp-emulator:latest .")
sh("docker tag kontxt-smtp-emulator:latest $registry:${VER}")
}
}
}
stage('Push images'){
steps{
script {
sh("eval \$(aws ecr get-login --no-include-email | sed 's|https://||')")
sh("docker push $registry:${VER}")
}
}
}
}
post {
always {
// make sure that the Docker image is removed
sh("docker rmi $registry:${VER}")
}
}
}