-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
66 lines (64 loc) · 1.73 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
pipeline {
agent any
environment {
ECR_REGISTRY = "735731564843.dkr.ecr.us-west-1.amazonaws.com/helloworldapp"
ECR_REGION = "us-west-1"
DOCKER_IMAGE = "vproapp"
SLACK_CHANNEL = "#jenkinsci_job"
}
stages {
/* stage('Generate artifact')
{
agent{
docker { image 'maven:3.8.1-adoptopenjdk-11'}
}
steps{
sh 'mvn clean install -Dskiptests'
}
} */
stage('Build Docker image') {
steps {
sh "docker build -t $DOCKER_IMAGE . "
}
}
stage('Login to ECR') {
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'awscredentials', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh "aws ecr get-login-password --region $ECR_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY"
}
}
}
stage('Push Docker image to ECR') {
steps {
sh "docker tag $DOCKER_IMAGE:latest $ECR_REGISTRY/$DOCKER_IMAGE:latest"
sh "docker push $ECR_REGISTRY/$DOCKER_IMAGE:latest"
}
}
}
post {
always {
slackSend(
color: getColor(),
message: getMessage(),
channel: env.SLACK_CHANNEL,
tokenCredentialId: 'slacklogin'
)
}
}
}
def getColor() {
if (currentBuild.result == 'SUCCESS') {
return 'good'
} else if (currentBuild.result == 'FAILURE') {
return 'danger'
} else {
return 'warning'
}
}
def getMessage() {
def message = "*Build ${currentBuild.result}:* ${currentBuild.fullDisplayName}"
if (env.BUILD_URL) {
message += "\n${env.BUILD_URL}"
}
return message
}