This repository has been archived by the owner on Mar 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helpers.groovy
111 lines (95 loc) · 5.29 KB
/
Helpers.groovy
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package ch.softozor.pipeline
def getBackendE2eManifests(installJps, e2eJps, jpsBaseUrl) {
sh "curl -o $installJps $jpsBaseUrl/manifest.jps"
sh "curl -o $e2eJps $jpsBaseUrl/e2e/e2e.jps"
}
def getFrontendE2eManifests(installJps, e2eJps, jpsBaseUrl) {
sh "curl -o $installJps $jpsBaseUrl/manifest.jps"
sh "curl -o $e2eJps $jpsBaseUrl/e2e/e2e.jps"
}
def publishBackendDockerImage(backendName, branch, enableDevTools, imageType) {
DOCKER_REPO = "shopozor/$backendName:$imageType-$branch"
sh "docker login -u $DOCKER_CREDENTIALS_USR -p $DOCKER_CREDENTIALS_PSW"
sh "docker build --build-arg ENABLE_DEV_TOOLS=$enableDevTools --network=host -t $DOCKER_REPO ."
sh "docker push $DOCKER_REPO"
}
def publishFrontendDockerImage(frontendName, branch, graphqlApi, enableDevTools, imageType) {
DOCKER_REPO = "shopozor/$frontendName:$imageType-$branch"
sh "cp ./$imageType/Dockerfile ."
sh "cp ./$imageType/.dockerignore ."
sh "docker login -u $DOCKER_CREDENTIALS_USR -p $DOCKER_CREDENTIALS_PSW"
sh "docker build --build-arg GRAPHQL_API=$graphqlApi --build-arg ENABLE_DEV_TOOLS=$enableDevTools --network=host -t $DOCKER_REPO ."
sh "docker push $DOCKER_REPO"
}
def getJelasticScript(scriptFile) {
sh "curl -o $scriptFile https://raw.githubusercontent.com/shopozor/jelastic-shared-library/master/$scriptFile"
sh "dos2unix $scriptFile"
sh "chmod u+x $scriptFile"
}
def deploy(installJps, appName, envName, branch, imageType) {
tag = "$imageType-$branch"
sh "sed -i \"s/APP_NAME/$appName/g\" $installJps"
sh "sed -i \"s/IMAGE_TYPE/$imageType/g\" $installJps"
sh "sed -i \"s/BRANCH/$branch/g\" $installJps"
getJelasticScript('helpers.sh')
SCRIPT_TO_RUN = 'deploy-to-jelastic.sh'
getJelasticScript(SCRIPT_TO_RUN)
sh "./$SCRIPT_TO_RUN $JELASTIC_APP_CREDENTIALS_USR $JELASTIC_APP_CREDENTIALS_PSW $JELASTIC_CREDENTIALS_USR $JELASTIC_CREDENTIALS_PSW $envName cp $installJps $tag"
}
def tagAndPush(tag, description) {
originUrl = "https://$GITHUB_CREDENTIALS_USR:$GITHUB_CREDENTIALS_PSW@" + GIT_URL.drop(8)
sh "git remote rm origin"
sh "git remote add origin $originUrl"
sh "git tag $tag -m \"$description\""
sh "git push origin $tag"
sh "git checkout $tag"
}
def runE2eTests(e2eJps, envName, appName, imageType) {
sh "sed -i \"s/APP_NAME/$appName/g\" $e2eJps"
sh "sed -i \"s/IMAGE_TYPE/$imageType/g\" $e2eJps"
getJelasticScript('helpers.sh')
SCRIPT_TO_RUN = 'run-e2e.sh'
getJelasticScript(SCRIPT_TO_RUN)
sh "./$SCRIPT_TO_RUN $JELASTIC_APP_CREDENTIALS_USR $JELASTIC_APP_CREDENTIALS_PSW $JELASTIC_CREDENTIALS_USR $JELASTIC_CREDENTIALS_PSW $envName cp $e2eJps"
}
def resetDatabase(e2eJps, envName, appName, imageType) {
runE2eTests(e2eJps, envName, appName, imageType)
}
def deleteFolder(folderName) {
dir(folderName) {
deleteDir()
}
}
def mountRemoteFolder(targetEnvName, targetNodeGroup, targetPath, sourceEnvName, sourceNodeGroup, sourcePath) {
getJelasticScript('helpers.sh')
SCRIPT_TO_RUN = 'mount-remote-folder.sh'
getJelasticScript(SCRIPT_TO_RUN)
sh "./$SCRIPT_TO_RUN $JELASTIC_APP_CREDENTIALS_USR $JELASTIC_APP_CREDENTIALS_PSW $JELASTIC_CREDENTIALS_USR $JELASTIC_CREDENTIALS_PSW $targetEnvName $targetNodeGroup $targetPath $sourceEnvName $sourceNodeGroup $sourcePath"
}
def retrieveTestResults(jenkinsEnvName, targetNodeGroup, targetPath, frontendName, sourceNodeGroup) {
// we create the frontendName folder in the case where we run the e2e tests from the backend
// in that case, we run the tests on the consumer and management frontends --> all results are coming to
// the jenkins, from both frontends!
sh "rm -Rf ${frontendName} && mkdir ${frontendName}"
// here we mount the /home/node of the frontend on /mnt/frontendName of jenkins
mountRemoteFolder(jenkinsEnvName, targetNodeGroup, targetPath, frontendName, sourceNodeGroup, PATH_TO_TEST_RESULTS)
sh "if test -d \"${targetPath}/cypress/${SCREENSHOTS_FOLDER}\"; then cp -R ${targetPath}/cypress/${SCREENSHOTS_FOLDER} ./${frontendName}/${SCREENSHOTS_FOLDER}; fi"
sh "if test -d \"${targetPath}/cypress/${VIDEOS_FOLDER}\"; then cp -R ${targetPath}/cypress/${VIDEOS_FOLDER} ./${frontendName}/${VIDEOS_FOLDER}; fi"
sh "if test -d \"${targetPath}/${TEST_REPORTS_FOLDER}\"; then cp -R ${targetPath}/${TEST_REPORTS_FOLDER} ./${frontendName}/${TEST_REPORTS_FOLDER}; fi"
}
def buildArtifacts() {
archiveArtifacts artifacts: "**/${VIDEOS_FOLDER}/**/*.mp4, **/${SCREENSHOTS_FOLDER}/**/*.png"
junit "**/${TEST_REPORTS_FOLDER}/*.xml"
}
def stopEnvironment(envName) {
getJelasticScript('helpers.sh')
SCRIPT_TO_RUN = 'stop-jelastic-env.sh'
getJelasticScript(SCRIPT_TO_RUN)
sh "./$SCRIPT_TO_RUN $JELASTIC_APP_CREDENTIALS_USR $JELASTIC_APP_CREDENTIALS_PSW $JELASTIC_CREDENTIALS_USR $JELASTIC_CREDENTIALS_PSW $envName"
}
def generateSpecification(featureDir, repo, commitNb) {
sh "mono /opt/pickles/Pickles.exe --feature-directory=$featureDir --output-directory=specification --system-under-test-name=$repo --system-under-test-version=$commitNb --language=fr --documentation-format=dhtml --exp --et 'in-preparation'"
sh "sshpass -p $SOFTOZOR_CREDENTIALS_PSW ssh -o StrictHostKeyChecking=no $SOFTOZOR_CREDENTIALS_USR@softozor.ch 'rm -Rf ~/www/www.softozor.ch/shopozor/$repo/*'"
sh "sshpass -p $SOFTOZOR_CREDENTIALS_PSW scp -o StrictHostKeyChecking=no -r specification/* $SOFTOZOR_CREDENTIALS_USR@softozor.ch:~/www/www.softozor.ch/shopozor/$repo/"
}
return this