-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.Jenkinsfile
164 lines (148 loc) · 4.5 KB
/
deploy.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
160
161
162
163
164
#!groovy
def repo_owner = "pace-neutrons"
def release_id_description = (
"The IDs of the jobs that contain the target release artifacts.\n" +
"This parameter should have the form:\n\n" +
" PIPELINE_NAME, BUILD_NUMBER;\n" +
" PIPELINE_NAME, BUILD_NUMBER;\n" +
" ...\n" +
"With a comma separating job name and build number and a semi-colon " +
"separating entries, white-space is ignored.")
def get_agent() {
def agent_label = ''
withCredentials([string(credentialsId: 'pacewin_agent', variable: 'agent')]) {
agent_label = "${agent}"
}
return agent_label
}
def get_repo_name(String job_name) {
if (job_name.contains('Herbert/')) {
return 'Herbert'
} else if (job_name.contains('Horace/')) {
return 'Horace'
}
return ''
}
properties([
parameters([
string(
defaultValue: '',
description: 'The SHA of the commit to create the tag/release on.',
name: 'tag_sha',
trim: true
),
string(
defaultValue: '',
description: 'The version of this release (e.g. 3.4.1)',
name: 'version_number',
trim: true
),
text(
defaultValue: '',
description: release_id_description,
name: 'release_job_ids'
),
text(
defaultValue: '',
description: 'The description of this release to show on GitHub e.g. release notes. This should be formatted as markdown.',
name: 'release_body'
),
booleanParam(
defaultValue: true,
description: 'Tick if this release should be marked as a draft on GitHub.',
name: 'is_draft'
),
booleanParam(
defaultValue: false,
description: 'Tick if this release should be marked as a pre-release on GitHub.',
name: 'is_prerelease'
),
string(
defaultValue: get_repo_name(env.JOB_NAME),
description: 'The name of the repository to create the release in.',
name: 'repo_name'
)
])
])
pipeline {
agent { label get_agent() }
stages {
stage('Get-Artifacts') {
steps {
script {
List lines = env.release_job_ids.split(';')
for (String line : lines) {
if (line.trim()) {
List build = line.split(',')
String project_name = build[0].trim()
String build_num = build[1].trim()
echo "Copying artifact from build #${build_num} of ${project_name}"
copyArtifacts(
filter: "**/${repo_name}-*,*git-revision*,docs.*",
fingerprintArtifacts: true,
flatten: true,
projectName: "${project_name}",
selector: specific("${build_num}"),
target: '.'
)
}
}
}
}
}
stage('Validate-Packages') {
steps {
powershell """
./pwsh/Test-GitShaFiles \
-RequiredSHA ${tag_sha} \
-FileFilter \"*git-revision*\"
\$artifacts = (Get-ChildItem -Filter ${repo_name}-*).Name
./pwsh/Test-VersionNumbers \
-VersionNumber ${version_number} \
-ReleaseFileNames \$artifacts
"""
}
}
stage('Push-Release') {
steps {
withCredentials([string(credentialsId: 'GitHub_API_Token',
variable: 'api_token')]) {
powershell """
\$artifacts = (Get-ChildItem -Filter ${repo_name}-*).Name
./pwsh/Deploy-ToGitHub \
-AssetPaths \$artifacts \
-AuthToken \${env:api_token} \
-GitSHA ${tag_sha} \
-ReleaseBody "${release_body}" \
-ReleaseName "v${version_number}" \
-RepoName ${repo_name} \
-RepoOwner ${repo_owner} \
-Draft \$${is_draft} \
-PreRelease \$${is_prerelease}
"""
}
}
}
stage('Push-Docs') {
steps {
withCredentials([string(credentialsId: 'GitHub_API_Token',
variable: 'api_token')]) {
// Creates version's docs folder on gh-pages
//powershell """
// ./pwsh/Docs -Action "push" \
// -ReleaseName "${version_number}" \
// -AuthToken \${env:api_token}
// ./pwsh/Docs -Action "update-stable" \
// -ReleaseName ${version_number} \
// -AuthToken \${env:api_token}
// """
}
}
}
}
post {
cleanup {
deleteDir()
}
}
}