-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.groovy
More file actions
41 lines (35 loc) · 1.4 KB
/
script.groovy
File metadata and controls
41 lines (35 loc) · 1.4 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
def testApp() {
echo 'testing the application...'
sh 'mvn test'
}
def incrementVersion() {
echo 'incrementing app version'
sh 'mvn build-helper:parse-version versions:set -DnewVersion=\\\${parsedVersion.majorVersion}.\\\${parsedVersion.minorVersion}.\\\${parsedVersion.nextIncrementalVersion} versions:commit'
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
def version = matcher[0][1]
env.VERSION = "$version-$BUILD_NUMBER"
}
def deployApp(String image, String ipAddress) {
echo 'deploying the application using shell script...'
def shellCmd = "bash ./deploy.sh ${image}:${VERSION}"
def ec2Instance = "ec2-user@${ipAddress}"
sshagent(['aws-ec2']) {
sh "scp deploy.sh ${ec2Instance}:/home/ec2-user"
sh "scp docker-compose.yaml ${ec2Instance}:/home/ec2-user"
sh "ssh -o StrictHostKeyChecking=no ${ec2Instance} ${shellCmd}"
}
}
def commitVersion() {
withCredentials([usernamePassword(credentialsId: 'github', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
sh 'git config --global user.email "jenkins@example.com"'
sh 'git config --global user.name "jenkins"'
sh "git status"
sh "git branch"
sh "git config --list"
sh "git remote set-url origin https://${USERNAME}:${PASSWORD}@github.com/explicit-logic/aws-module-9.4"
sh 'git add .'
sh "git commit -m 'ci: version ${VERSION}'"
sh 'git push origin HEAD:main'
}
}
return this