-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
92 lines (84 loc) · 3.12 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
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: "10"))
}
agent any
environment {
ECR_REPO = '243060292047.dkr.ecr.eu-west-1.amazonaws.com/tech-talk'
teams_url = "https://majidalfuttaim.webhook.office.com/webhookb2/9c4d9eba-3f45-43eb-b60f-01487a9fc92e@b09ab65e-9063-4862-afa2-d75ab48bba74/JenkinsCI/2d1c5570cf2f4f638211201e331a823f/ea36fd4b-baff-4d76-b4f3-ddf2a3c0cf1d"
ENVIRONMENT = "${env.BRANCH_NAME == 'develop' ? 'dev' : 'prod'}"
}
stages {
stage('Build start notification') {
steps {
office365ConnectorSend (
color: '#223c6e',
message: "TechTalk:Started <br/>\nJob: '${env.JOB_NAME}' <br/>\nBuild: '[${env.BUILD_NUMBER}]' <br/>\nBranch: '${env.BRANCH_NAME}'",
status: 'Started',
webhookUrl: "${env.teams_url}"
)
}
}
stage('Commit Details') {
steps {
script {
env.pr_id = sh (script: 'git log -n 1 --pretty=format:"%s" |cut -d "#" -f2 | cut -d" " -f1 |tr -dc "0-9"', returnStdout: true).trim()
env.pr_author = sh (script: 'git log -n 1 --pretty=format:"%an"', returnStdout: true).trim()
}
}
}
stage('Build-Push Image') {
when {
anyOf {
branch 'develop'
branch 'master'
}
}
steps {
sh script:'''
docker build --no-cache -t $ECR_REPO:$ENVIRONMENT-latest . --network host
'''
}
}
}
stage('Test') {
when {
anyOf {
branch 'develop'
branch 'master'
}
}
steps {
sh script:'''
echo Do tests here :)
'''
}
}
}
stage('Push') {
when {
anyOf {
branch 'develop'
branch 'master'
}
}
steps {
sh script:'''
/usr/local/bin/aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin $ECR_REPO
docker push $ECR_REPO:$ENVIRONMENT-latest
'''
}
}
}
post {
always {
office365ConnectorSend (
color: "${currentBuild.result == 'SUCCESS' ? '#40a832' : '#FF0000'}",
message: "Tech-Talk-Build:${currentBuild.result} for PR#'${env.pr_id}' <br/>\nPR Author: '${env.pr_author}' <br/>\nJob: '${env.JOB_NAME}' <br/>\nBuild: '[${env.BUILD_NUMBER}]' <br/>\nBranch: '${env.BRANCH_NAME}'",
status: "${currentBuild.result}",
webhookUrl: "${env.teams_url}"
)
cleanWs()
}
}
}