-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
71 lines (59 loc) · 2.04 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
pipeline {
agent any
options {
skipStagesAfterUnstable()
buildDiscarder(logRotator(numToKeepStr: '30'))
timestamps()
}
tools {
maven 'maven-3.8.6'
}
parameters {
string(name: "image_name", defaultValue: 'java-discord-help-bot')
string(name: "image_tag", defaultValue: 'latest')
booleanParam(name: "push_image", defaultValue: true)
}
stages {
stage('Build JAR & image') {
steps {
sh 'mvn -B -P docker clean package -DskipTests'
}
}
stage('Run automation tests') {
steps {
script {
withCredentials([string(credentialsId: 'javaDiscordHelpBotAutomationTestToken', variable: 'TOKEN')]) {
sh "mvn -P automation clean install \"-Ddiscord.token=$TOKEN\" -DskipTests=true"
}
docker.withRegistry("", "generalTaoDockerHub") {
sh "mvn -Dtest=discord.automation.runners.CucumberRunnerIT test"
}
}
}
}
stage("Push to Dockerhub") {
when {
equals expected: "true",
actual: "${params.push_image}"
}
steps {
script {
echo "Pushing the image to docker hub"
def repositoryName = "generaltao725/${params.image_name}"
docker.withRegistry("", "generalTaoDockerHub") {
def image = docker.image(repositoryName);
try {
image.push("latest")
image.push("0.0.0")
} catch(Exception ex) {
println(ex);
image.push("latest")
image.push("0.0.0")
}
}
sh "docker rmi -f ${repositoryName} "
}
}
}
}
}