This repository was archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathJenkinsfile
143 lines (122 loc) · 5.84 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!groovy
pipeline {
agent any
options {
timestamps()
skipStagesAfterUnstable()
}
stages {
stage('Build') {
steps {
script {
println("Starting codewind-openapi-eclipse build ...")
def sys_info = sh(script: "uname -a", returnStdout: true).trim()
println("System information: ${sys_info}")
sh '''
java -version
which java
'''
dir('dev') {
sh './gradlew --stacktrace'
}
dir('dev/ant_build/artifacts') {
stash name: 'codewind-openapi-eclipse-test.zip', includes: 'codewind-openapi-eclipse-test-*.zip'
sh 'rm codewind-openapi-eclipse-test-*.zip'
stash name: 'codewind-openapi-eclipse-zip', includes: 'codewind-openapi-eclipse-*.zip'
}
}
}
}
stage('Test on docker agent') {
agent {
label "docker-build"
}
steps {
script {
try {
dir('dev/ant_build/artifacts') {
unstash 'codewind-openapi-eclipse-test.zip'
unstash 'codewind-openapi-eclipse-zip'
}
sh '''#!/usr/bin/env bash
docker build --no-cache -t test-image ./dev
export CWD=$(pwd)
echo "Current directory is ${CWD}"
docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${CWD}/dev:/development test-image
'''
} finally {
junit 'dev/junit-results.xml'
}
}
}
post {
always {
sh '''#!/usr/bin/env bash
# Docker system prune
echo "Docker system prune ..."
docker system df
docker system prune -a --volumes -f
docker builder prune -a -f
docker system df
df -lh
'''
echo 'Clean up workspace'
deleteDir() /* clean up our workspace */
}
}
}
stage('Deploy') {
// This when clause disables PR build uploads; you may comment this out if you want your build uploaded.
when {
beforeAgent true
not {
changeRequest()
}
}
options {
skipDefaultCheckout()
}
steps {
sshagent ( ['projects-storage.eclipse.org-bot-ssh']) {
println("Deploying codewind-openapi-eclipse to archive area...")
dir("$WORKSPACE/dev/ant_build/artifacts") {
unstash 'codewind-openapi-eclipse-zip'
}
sh '''
export REPO_NAME="codewind-openapi-eclipse"
export OUTPUT_NAME="codewind-openapi-eclipse"
export OUTPUT_DIR="$WORKSPACE/dev/ant_build/artifacts"
export ARCHIVE_AREA_URL="https://archive.eclipse.org/codewind/$REPO_NAME"
export LATEST_DIR="latest"
export BUILD_INFO="build_info.properties"
export sshHost="genie.codewind@projects-storage.eclipse.org"
export deployDir="/home/data/httpd/archive.eclipse.org/codewind/$REPO_NAME"
if [ -z $CHANGE_ID ]; then
UPLOAD_DIR="$GIT_BRANCH/$BUILD_ID"
BUILD_URL="$ARCHIVE_AREA_URL/$UPLOAD_DIR"
ssh $sshHost rm -rf $deployDir/$GIT_BRANCH/$LATEST_DIR
ssh $sshHost mkdir -p $deployDir/$GIT_BRANCH/$LATEST_DIR
cp $OUTPUT_DIR/$REPO_NAME-*.zip $OUTPUT_DIR/$REPO_NAME.zip
scp $OUTPUT_DIR/$REPO_NAME.zip $sshHost:$deployDir/$GIT_BRANCH/$LATEST_DIR/$REPO_NAME.zip
echo "# Build date: $(date +%F-%T)" >> $OUTPUT_DIR/$BUILD_INFO
echo "build_info.url=$BUILD_URL" >> $OUTPUT_DIR/$BUILD_INFO
SHA1=$(sha1sum ${OUTPUT_DIR}/${OUTPUT_NAME}.zip | cut -d ' ' -f 1)
echo "build_info.SHA-1=${SHA1}" >> $OUTPUT_DIR/$BUILD_INFO
unzip $OUTPUT_DIR/$REPO_NAME-*.zip -d $OUTPUT_DIR/repository
scp -r $OUTPUT_DIR/repository $sshHost:$deployDir/$GIT_BRANCH/$LATEST_DIR/repository
scp $OUTPUT_DIR/$BUILD_INFO $sshHost:$deployDir/$GIT_BRANCH/$LATEST_DIR/$BUILD_INFO
rm $OUTPUT_DIR/$BUILD_INFO
rm $OUTPUT_DIR/$REPO_NAME.zip
rm -rf $OUTPUT_DIR/repository
else
UPLOAD_DIR="pr/$CHANGE_ID/$BUILD_ID"
fi
ssh $sshHost rm -rf $deployDir/${UPLOAD_DIR}
ssh $sshHost mkdir -p $deployDir/${UPLOAD_DIR}
scp -r $OUTPUT_DIR/* $sshHost:$deployDir/${UPLOAD_DIR}
'''
}
}
}
}
}