-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
76 lines (63 loc) · 2.4 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
67
68
69
70
71
72
73
74
75
76
pipeline {
agent any
environment {
MANGO_SECRET_1 = credentials('0b5cf62f-5c0f-43f9-a32e-0d006eb2a5a6')
}
stages {
stage('Credentials') {
steps {
sh 'echo "$MANGO_SECRET_1" | base64'
// Simulate a failed build
// script {
// currentBuild.result = 'FAILURE'
// echo "The build failed forcefully!"
// }
}
}
stage('Login Docker Hub') {
// SKIP STAGE DUE TO WHEN CONDITIONAL
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps {
withCredentials([usernamePassword(credentialsId: 'docker-hub-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
// WARNING! Using --password via the CLI is insecure. Use --password-stdin.
// sh 'docker login -u $USERNAME -p $PASSWORD'
// The following example reads a password from a variable, and passes it to the docker login command using STDIN:
// sh 'echo -n "$PASSWORD" | docker login -u $USERNAME --password-stdin'
sh 'docker login -u $USERNAME -p $PASSWORD'
}
echo 'Try pulling image from private image repository'
sh 'docker pull xblue/caysixcustomimg:latest'
sh 'docker images'
}
}
stage('Build') {
// SKIP STAGE DUE TO WHEN CONDITIONAL
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps {
echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"
echo "Building docker image..."
sh 'docker build -t express-mango:1.0 .'
}
}
stage('Deploy') {
// SKIP STAGE DUE TO WHEN CONDITIONAL
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps {
echo "Run docker image and expose port 4444:3000"
sh 'docker run -d -p 4444:3000 express-mango:1.0'
}
}
}
}