-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkins-file
More file actions
63 lines (55 loc) · 2 KB
/
Jenkins-file
File metadata and controls
63 lines (55 loc) · 2 KB
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
pipeline {
agent any
environment {
AWS_ACCOUNT_ID = "796008141374"
AWS_REGION = "eu-north-1"
IMAGE_REPO_NAME = "amazon-ecr-001"
IMAGE_TAG = "v1"
REPOSITORY_URI = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${IMAGE_REPO_NAME}"
}
stages {
stage('Checkout Git Repo') {
steps {
echo "📥 Cloning Git repository..."
git url: 'https://github.com/cloudwavetechnologies/Gitpractice-Repo.git', branch: 'Master'
}
}
stage('Build Docker Image') {
steps {
echo "🐳 Building Docker image..."
sh "docker build -t ${IMAGE_REPO_NAME}:${IMAGE_TAG} ."
}
}
stage('Tag Image for ECR') {
steps {
echo "🏷️ Tagging image for ECR..."
sh "docker tag ${IMAGE_REPO_NAME}:${IMAGE_TAG} ${REPOSITORY_URI}:${IMAGE_TAG}"
}
}
stage('Login & Push to ECR') {
steps {
withCredentials([usernamePassword(
credentialsId: 'aws-creds',
usernameVariable: 'AWS_ACCESS_KEY_ID',
passwordVariable: 'AWS_SECRET_ACCESS_KEY'
)]) {
sh """
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
aws ecr get-login-password --region ${AWS_REGION} | \
docker login --username AWS --password-stdin ${REPOSITORY_URI}
docker push ${REPOSITORY_URI}:${IMAGE_TAG}
"""
}
}
}
}
post {
success {
echo "✅ Docker image pushed to ECR: ${REPOSITORY_URI}:${IMAGE_TAG}"
}
failure {
echo "❌ Pipeline failed. Check logs for details."
}
}
}