forked from KlausMikhaelson/SharkTanks-Debug_Thugs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
53 lines (52 loc) · 1.65 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
pipeline {
agent{
docker {
image 'docker:latest'
registryUrl 'https://index.docker.io/v1/'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
stages {
stage('Checkout') {
steps {
sh 'echo passed'
//git branch: 'main', url: 'https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero.git'
}
}
stage('Build and Push Docker Image') {
environment {
DOCKER_IMAGE = "yashpimple22/web-game:${BUILD_NUMBER}"
// DOCKERFILE_LOCATION = "java-maven-sonar-argocd-helm-k8s/spring-boot-app/Dockerfile"
REGISTRY_CREDENTIALS = credentials('docker-cred')
}
steps {
script {
sh 'docker build -t ${DOCKER_IMAGE} .'
def dockerImage = docker.image("${DOCKER_IMAGE}")
docker.withRegistry('https://index.docker.io/v1/', "docker-cred") {
dockerImage.push()
}
}
}
}
stage('Updating deployment.yaml'){
environment {
GIT_REPO_NAME = <REPO_NAME>
GIT_USER_NAME = <USER_NAME>
}
steps {
withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
sh '''
git config user.email <EMAIL>
git config user.name <USER_NAME>
BUILD_NUMBER=${BUILD_NUMBER}
sed -i "s/latest/${BUILD_NUMBER}/g" Manifests/deployment.yaml
git add Manifests/deployment.yaml
git commit -m "Update deployment image to version ${BUILD_NUMBER}"
git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main
'''
}
}
}
}
}