-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
86 lines (75 loc) · 2.76 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
77
78
79
80
81
82
83
84
85
86
pipeline {
agent any
triggers {
cron 'H 22 * * *'
}
options {
buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '10'))
skipStagesAfterUnstable()
}
environment {
DIST_FILE = "ivy-website-update.tar"
}
stages {
stage('build') {
steps {
script {
docker.build('db', '-f docker/mariadb/Dockerfile docker/mariadb').withRun() { dbContainer ->
docker.build('apache', '-f docker/apache/Dockerfile docker/apache').inside("--link ${dbContainer.id}:db") {
sh 'composer install --no-dev --no-progress'
sh "tar -cf ${env.DIST_FILE} src vendor"
archiveArtifacts env.DIST_FILE
stash name: 'website-tar', includes: env.DIST_FILE
sh 'composer install --no-progress'
sh './vendor/bin/phpunit --log-junit phpunit-junit.xml || exit 0'
junit 'phpunit-junit.xml'
script {
if (env.BRANCH_NAME == 'master') {
sh 'composer require --dev cyclonedx/cyclonedx-php-composer --no-progress'
sh 'composer CycloneDX:make-sbom --output-format=JSON --output-file=bom.json'
withCredentials([string(credentialsId: 'dependency-track', variable: 'API_KEY')]) {
sh 'curl -v --fail -X POST https://api.dependency-track.ivyteam.io/api/v1/bom \
-H "Content-Type: multipart/form-data" \
-H "X-API-Key: ' + API_KEY + '" \
-F "autoCreate=true" \
-F "projectName=update.axonivy.com" \
-F "projectVersion=master" \
-F "[email protected]"'
}
}
}
}
}
}
}
}
stage('deploy') {
when {
branch 'master'
}
agent {
docker {
image 'axonivy/build-container:ssh-client-1'
}
}
steps {
sshagent(['zugprojenkins-ssh']) {
script {
unstash 'website-tar'
def targetFolder = "/home/axonivya/deployment/ivy-website-update-" + new Date().format("yyyy-MM-dd_HH-mm-ss-SSS");
def targetFile = targetFolder + ".tar"
def host = '[email protected]'
// copy
sh "scp ivy-website-update.tar $host:$targetFile"
// untar
sh "ssh $host mkdir $targetFolder"
sh "ssh $host tar -xf $targetFile -C $targetFolder"
sh "ssh $host rm -f $targetFile"
// symlink
sh "ssh $host ln -fns $targetFolder/src/web /home/axonivya/www/update.axonivy.com/linktoweb"
}
}
}
}
}
}