-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathJenkinsfile
58 lines (52 loc) · 1.79 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
pipeline {
agent any
environment {
IMAGE_REPO_NAME="log4shellpub"
//REPLACE XXX WITH YOUR STUDENT NUMBER
IMAGE_TAG= "stdXXX"
REPOSITORY_URI = "public.ecr.aws/f9n2h3p5/log4shellpub"
AWS_DEFAULT_REGION = "us-east-1"
}
stages {
stage('Logging into AWS ECR') {
steps {
script {
sh """aws ecr-public get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${REPOSITORY_URI} """
}
}
}
stage('Clone repository') {
steps {
script{
checkout scm
}
}
}
// Building Docker images
stage('Building image') {
steps{
script {
dockerImage = docker.build "${IMAGE_REPO_NAME}:${IMAGE_TAG}-${env.BUILD_NUMBER}"
}
}
}
// Uploading Docker images into AWS ECR
stage('Pushing to ECR') {
steps{
script {
sh """docker tag ${IMAGE_REPO_NAME}:${IMAGE_TAG}-${env.BUILD_NUMBER} ${REPOSITORY_URI}:$IMAGE_TAG-${env.BUILD_NUMBER}"""
sh """docker push ${REPOSITORY_URI}:${IMAGE_TAG}-${env.BUILD_NUMBER}"""
}
}
}
stage('Deploy'){
steps {
sh 'sed -i "s/<TAG>/${IMAGE_TAG}-${BUILD_NUMBER}/" deployment.yml'
sh 'kubectl apply -f deployment.yml'
/*
//If you are sure this deployment is already running and want to change the container image version, then you can use:
sh 'kubectl set image deployments/dvwa 371571523880.dkr.ecr.us-east-2.amazonaws.com/dvwaxperts:${BUILD_NUMBER}'*/
}
}
}
}