-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathJenkinsfile.publish-artifactory
More file actions
99 lines (89 loc) · 3.51 KB
/
Copy pathJenkinsfile.publish-artifactory
File metadata and controls
99 lines (89 loc) · 3.51 KB
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
/**
* Downloads a DDK release p2 update site from GitHub Releases and uploads it
* to the internal Artifactory p2-releases repository.
*
* Parameters:
* RELEASE_VERSION - The release version to publish (e.g. "18.0.0")
* ARTIFACTORY_REPO_URL - Base URL of the Artifactory repository
* ARTIFACTORY_SERVER_ID - Server ID in ~/.m2/settings.xml that holds the Artifactory credentials
*
* Required tools:
* curl, xmllint (available on the agent)
*/
pipeline {
agent { label 'linux' }
parameters {
string(
name: 'RELEASE_VERSION',
description: 'Release version to download from GitHub Releases and upload to Artifactory (e.g. 18.0.0)',
trim: true
)
string(
name: 'ARTIFACTORY_REPO_URL',
description: 'Base URL of the Artifactory repository',
trim: true
)
string(
name: 'ARTIFACTORY_SERVER_ID',
description: 'Server ID in ~/.m2/settings.xml that holds the Artifactory credentials',
trim: true
)
}
environment {
GH_RELEASES_BASE_URL = 'https://github.com/dsldevkit/dsl-devkit/releases/download'
}
stages {
stage('Validate') {
steps {
script {
if (!params.RELEASE_VERSION) {
error 'RELEASE_VERSION parameter is required'
}
if (!params.ARTIFACTORY_REPO_URL) {
error 'ARTIFACTORY_REPO_URL parameter is required'
}
if (!params.ARTIFACTORY_SERVER_ID) {
error 'ARTIFACTORY_SERVER_ID parameter is required'
}
}
}
}
stage('Download from GitHub Releases') {
steps {
sh """
curl --fail --silent --show-error --location \\
"${GH_RELEASES_BASE_URL}/v${params.RELEASE_VERSION}/p2-update-site.zip" \\
-o "p2-update-site-${params.RELEASE_VERSION}.zip"
echo "Downloaded p2-update-site-${params.RELEASE_VERSION}.zip"
"""
}
}
stage('Upload to Artifactory') {
steps {
sh """
set +x
ARTIFACTORY_USER=\$(xmllint --xpath "string(//server[id='${ARTIFACTORY_SERVER_ID}']/username)" ~/.m2/settings.xml)
ARTIFACTORY_PASS=\$(xmllint --xpath "string(//server[id='${ARTIFACTORY_SERVER_ID}']/password)" ~/.m2/settings.xml)
# Upload and explode the archive in Artifactory
curl --fail --silent --show-error \\
-u "\${ARTIFACTORY_USER}:\${ARTIFACTORY_PASS}" \\
-H "X-Explode-Archive: true" \\
--upload-file "p2-update-site-${params.RELEASE_VERSION}.zip" \\
"${ARTIFACTORY_REPO_URL}/${params.RELEASE_VERSION}/p2-update-site-${params.RELEASE_VERSION}.zip"
echo "Successfully uploaded release ${params.RELEASE_VERSION} to Artifactory"
"""
}
}
}
post {
always {
cleanWs()
}
success {
echo "Release ${params.RELEASE_VERSION} published to Artifactory at: ${ARTIFACTORY_REPO_URL}/${params.RELEASE_VERSION}/"
}
failure {
echo "Failed to publish release ${params.RELEASE_VERSION} to Artifactory"
}
}
}