-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
71 lines (71 loc) · 2.48 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
pipeline {
agent {
label 'ubuntu-latest'
}
environment {
MAVEN_USERNAME = credentials('MAVEN_USERNAME')
MAVEN_PASSWORD = credentials('MAVEN_PASSWORD')
GPG_PRIVATE_KEY = credentials('GPG_PRIVATE_KEY')
GPG_PASSPHRASE = credentials('GPG_PASSPHRASE')
}
stages {
stage('Run Only on Tag') {
when {
expression {
// Matches tags like rls_0.1.0, rls_0.1.1, etc.
return env.BRANCH_NAME ==~ /^rls_\d+\.\d+\.\d+$/
}
}
steps {
echo "Running on tag: $env.BRANCH_NAME"
}
stages {
stage('Pre-check for Environment Variables') {
steps {
script {
if (!env.MAVEN_USERNAME || !env.MAVEN_PASSWORD || !env.GPG_PRIVATE_KEY || !env.GPG_PASSPHRASE) {
error("Error: One or more required environment variables (MAVEN_USERNAME, MAVEN_PASSWORD, GPG_PRIVATE_KEY, GPG_PASSPHRASE) are not defined.")
}
echo "All necessary environment variables are defined."
}
}
}
stage('Checkout Code') {
steps {
checkout scm
}
}
stage('Install GPG Secret Key') {
steps {
sh '''
echo "$GPG_PRIVATE_KEY" | gpg --batch --import
'''
}
}
stage('Set up Maven') {
steps {
sh '''
# Install Java 8 and Maven for deployment to Maven Central
sudo apt-get update
sudo apt-get install -y openjdk-8-jdk maven
'''
}
}
stage('Publish to Maven Central') {
steps {
sh '''
mvn --no-transfer-progress --batch-mode \
-Dgpg.passphrase=$GPG_PASSPHRASE \
clean deploy -P release-sign-artifacts -e
'''
}
}
}
}
}
post {
always {
cleanWs()
}
}
}