-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
159 lines (142 loc) · 3.83 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def updated = false;
pipeline {
triggers {
cron(env.BRANCH_NAME == 'main' ? 'H H * * 3' : '')
}
agent {
label 'Linux'
}
environment {
ARTEFACTS_SERVER = credentials ('deployment-server')
ARTEFACTS_PATH="/media/img/coreos"
ARTEFACTS_VERSIONS = "coreos.json"
}
stages {
stage('Initialize') {
parallel {
stage('Advertise start of build') {
steps {
slackSend color: "#4675b1", message: "${env.JOB_NAME} build #${env.BUILD_NUMBER} started :fire: (<${env.RUN_DISPLAY_URL}|Open>)"
}
}
stage('Print environments variables') {
steps {
sh 'printenv | sort'
}
}
}
}
stage('Set up prerequisites') {
parallel {
stage('Get ssh host key') {
steps {
sh '''
[ -d ~/.ssh ] || mkdir ~/.ssh && chmod 0700 ~/.ssh && touch ~/.ssh/known_hosts
if !(ssh-keygen -F $ARTEFACTS_SERVER)
then
ssh-keyscan -t ed25519 $ARTEFACTS_SERVER >> ~/.ssh/known_hosts
fi
'''
}
}
stage('Get fedora pgp keys') {
steps {
sh 'curl --no-progress-meter https://fedoraproject.org/fedora.gpg | gpg --import'
}
}
stage('Get last version') {
steps {
sshagent(credentials: ['Jenkins-Key']) {
sh '''
if scp jenkins@$ARTEFACTS_SERVER:/$ARTEFACTS_PATH/$ARTEFACTS_VERSIONS ./$ARTEFACTS_VERSIONS
then
echo "History found"
else
echo "History not found"
fi
'''
}
}
}
}
}
stage("Download ... Upload") {
matrix {
axes {
axis {
name 'STREAM'
values 'stable', 'next', 'testing'
}
axis {
name 'ARCH'
values 'x86_64', 'aarch64'
}
axis {
name 'ARTIFACT'
values 'metal'
}
axis {
name 'FORMAT'
values 'pxe'
}
}
excludes {
exclude {
axis {
name 'STREAM'
values 'testing'
}
}
exclude {
axis {
name 'ARCH'
values 'aarch64'
}
}
}
stages {
stage("Getting CoreOS artefacts") {
steps {
sh './Update.sh --stream $STREAM --arch $ARCH --artifact $ARTIFACT --format $FORMAT --history $ARTEFACTS_VERSIONS --verbose true'
}
}
stage("Upload Files") {
when { expression { fileExists("${FORMAT}.${ARTIFACT}.${ARCH}.${STREAM}") } }
steps {
sshagent(credentials: ['Jenkins-Key']) {
sh '''
files=$(cat $FORMAT.$ARTIFACT.$ARCH.$STREAM)
echo uploading $FORMAT.$ARTIFACT.$ARCH.$STREAM files
scp $files jenkins@$ARTEFACTS_SERVER:/media/img/coreos/
'''
script { updated = true }
}
}
}
}
}
}
stage("Upload versions update") {
when { expression { updated == true } }
steps {
sshagent(credentials: ['Jenkins-Key']) {
sh '''
scp ./$ARTEFACTS_VERSIONS jenkins@$ARTEFACTS_SERVER:/$ARTEFACTS_PATH/$ARTEFACTS_VERSIONS
'''
archiveArtifacts ARTEFACTS_VERSIONS
}
}
}
}
post {
success {
slackSend color: "#4675b1", message: "${env.JOB_NAME} successfully built :blue_heart: !"
}
failure {
slackSend color: "danger", message: "${env.JOB_NAME} build failed :poop: !"
}
cleanup {
cleanWs()
}
}
}