-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-working-code
80 lines (79 loc) · 3.83 KB
/
Jenkinsfile-working-code
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
pipeline {
agent any
environment {
DOCKER_IMAGE = "docker-test-server-12345"
CONTAINER_NAME = "server-test-41"
///DOCKERHUB = credentials('dockerhub')
//HUB_CRED = credentials('dockerhubpwd')
}
stages {
stage ('Clone Repository') {
steps {
echo "Checkout Git Repo"
// git credentialsId: 'github', url: 'https://github.com/radhakrishna4687/:${GITHUB_BRANCH}'
git 'https://github.com/radhakrishna4687/java-webapp.git'
echo "Complted the Checkout the Git"
}
}
stage ('Build Docker Image') {
steps {
sh '''
docker build . -t ${DOCKER_IMAGE}
docker images
'''
//sh "docker build . -t radhakrishna4687/test-image-1:${DOCKER_TAG} "
}
}
stage ('Run the Docker Container') {
steps {
sh '''
docker run -itd --name=${CONTAINER_NAME} -p 8093:8080 ${DOCKER_IMAGE}
docker ps
docker inspect ${CONTAINER_NAME}
'''
}
}
stage ('Docker image push to Dockerhub Repository') {
steps {
sh 'docker tag ${DOCKER_IMAGE} radhakrishna4687/sample-java-test-web-app:0.0.1'
echo 'Fetching the AWS Secret Managers key In Text format'
sh 'aws secretsmanager get-secret-value --secret-id dockerhubpwd --query SecretString --output text'
sh '''
aws secretsmanager list-secrets --output json
aws secretsmanager describe-secret --secret-id dockerhubpwd
aws secretsmanager list-secret-version-ids --secret-id dockerhubpwd
aws secretsmanager list-secrets
'''
echo 'Sucessfully fetch the AWS secret Key'
}
}
stage ('Push docker image to DockerHub') {
steps {
//withCredentials([usernamePassword(credentialsId: '${HUB_CRED}',usernameVariable: '${HUB_CRED_USR}', passwordVariable: '${HUB_CRED_PSW}')]) {
withDockerRegistry([ credentialsId: 'dockerhubpwd', url: '' ]) {
//script {
// username = sh (script: "aws secretsmanager get-secret-value --region us-east-1 --secret-id dockerhubpwd | jq -r .SecretString | jq -r .username", returnStdout: true)
// password = sh (script: "aws secretsmanager get-secret-value --region us-east-1 --secret-id dockerhubpwd | jq -r .SecretString | jq -r .password", returnStdout: true)
// withCredentials([usernamePassword(credentialsId: '${DOCKERHUB}',usernameVariable: 'DOCKER_USR', passwordVariable: 'DOCKER_PSW')]) {
//withDockerRegistry([ credentialsId: "${HUB_CRED_USR}:${HUB_CRED_PSW}", url: "" ]) {
//withDockerRegistry([ credentialsId: "dockerhub", url: "" ]) {
//withCredentials([string(credentialsId: 'dockerhubcred', variable: 'dockerhubpwd')]) {
//withCredentials([string(credentialsId: 'dockerhub', variable: 'dockerhubpwd')])
//sh 'sudo su -p root'
// sh 'docker login --username radhakrishna4687 --password-stdin ${dockerhubpwd}'
//sh 'docker push radhakrishna4687/harikrishna-web-app:v3'
sh 'docker push radhakrishna4687/sample-java-test-web-app:0.0.1'
}
}
}
stage ('Docker remove contaner and image') {
steps {
sh '''
docker stop ${CONTAINER_NAME}
docker rm ${CONTAINER_NAME} --force
docker rmi ${DOCKER_IMAGE} --force
'''
}
}
}
}