forked from OpqTech/java-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
88 lines (75 loc) · 2.49 KB
/
Jenkinsfile
File metadata and controls
88 lines (75 loc) · 2.49 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
pipeline {
agent none
parameters {
string (defaultValue: 'dev',description:'Enter the ENV value', name:'env.BRANCH_NAME')
choice (name: 'BRANCH_NAME', choices: ['master','dev','build'], description:'')
booleanParam defaultValue: true, name: 'my boolean'
}
environment {
GITHUB_KEY = credentials('my github token')
JENKINS_USER = credentials('jenkins-username')
}
triggers {
cron '5 * * * *'
pollSCM '* * * * *'
}
stages {
stage('checkout'){
agent {
label "sonar"
}
steps{
git 'https://github.com/OPQjuly23/java-example.git'
echo " Executing in $ENV envirnoment "
echo "This is my github token ${GITHUB_KEY}"
echo " This is my Jenkins username is ${JENKINS_USER_USR} "
echo " This is my jenkis password is ${JENKINS_USER_PSW} "
}
}
stage('stage-2 sonar') {
agent {
label "sonar"
}
steps {
withSonarQubeEnv(credentialsId: 'sonarqube-Token', installationName: 'sonar-server') {
// some block
sh 'mvn clean verify sonar:sonar'
}
}
}
stage('stage-3 maven build') {
agent {
label "Tomcat"
}
when {
expression { currentBuild.resultIsBetterOrEqualTo('SUCCESS') }
}
steps {
sh 'mvn clean install'
echo "executing ${branch} on checkout code"
}
}
stage('stage-4 deploy') {
agent {
label "Tomcat"
}
when {
expression { currentBuild.resultIsBetterOrEqualTo('SUCCESS') }
}
steps {
sshagent(['tomcatcred']) {
// some block
sh 'scp -o strictHostkeyChecking=no target/*.war [email protected]:/opt/tomcat/apache-tomcat-9.0.68/webapps/'
}
}
}
}
post {
success {
mail to:"[email protected]", subject:"SUCCESS: [job name=${env.JOB_NAME}] [Build no=${env.BUILD_NUMBER}][build url= ${env.BUILD_URL}]", body: "[job name=${env.JOB_NAME}] [Build no=${env.BUILD_NUMBER}][build url= ${env.BUILD_URL}] Build Success."
}
failure {
mail to:"[email protected]", subject:"FAILURE: ${env.JOB_NAME} [${env.BUILD_NUMBER} ${env.BUILD_URL}", body: "[job name=${env.JOB_NAME}] [Build no=${env.BUILD_NUMBER}][build url= ${env.BUILD_URL}] Build failure."
}
}
}