Skip to content

Commit 1b42fd6

Browse files
committed
add jenkins release pipeline
1 parent df95350 commit 1b42fd6

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

Jenkinsfile

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
AGENT_YAML = '''
2+
apiVersion: v1
3+
kind: Pod
4+
spec:
5+
containers:
6+
- name: maven
7+
image: maven:3.8.6-openjdk-8-slim
8+
tty: true
9+
resources:
10+
requests:
11+
memory: "1Gi"
12+
cpu: "500m"
13+
limits:
14+
memory: "1Gi"
15+
cpu: "500m"
16+
command:
17+
- cat
18+
'''
19+
20+
pipeline {
21+
22+
agent {
23+
kubernetes {
24+
defaultContainer 'maven'
25+
yaml AGENT_YAML
26+
}
27+
}
28+
29+
environment {
30+
GPG_SECRET = credentials('presto-release-gpg-secret')
31+
GPG_TRUST = credentials("presto-release-gpg-trust")
32+
GPG_PASSPHRASE = credentials("presto-release-gpg-passphrase")
33+
34+
GITHUB_OSS_TOKEN_ID = 'github-personal-access-token-prestodb'
35+
36+
SONATYPE_NEXUS_CREDS = credentials('presto-sonatype-nexus-creds')
37+
SONATYPE_NEXUS_PASSWORD = "$SONATYPE_NEXUS_CREDS_PSW"
38+
SONATYPE_NEXUS_USERNAME = "$SONATYPE_NEXUS_CREDS_USR"
39+
}
40+
41+
options {
42+
buildDiscarder(logRotator(numToKeepStr: '100'))
43+
disableConcurrentBuilds()
44+
disableResume()
45+
overrideIndexTriggers(false)
46+
timeout(time: 30, unit: 'MINUTES')
47+
timestamps()
48+
}
49+
50+
parameters {
51+
booleanParam(name: 'PERFORM_MAVEN_RELEASE',
52+
defaultValue: false,
53+
description: 'Release and update development version when running in the master')
54+
}
55+
56+
stages {
57+
stage('Setup') {
58+
steps {
59+
sh 'apt update && apt install -y bash build-essential git gpg python3 python3-venv'
60+
}
61+
}
62+
63+
stage ('Prepare to Release') {
64+
steps {
65+
script {
66+
env.REPO_CURRENT_VERSION = sh(
67+
script: 'mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -ntp -DforceStdout',
68+
returnStdout: true).trim()
69+
}
70+
echo "current version: ${REPO_CURRENT_VERSION}"
71+
72+
sh '''
73+
git config --global --add safe.directory ${PWD}
74+
git config --global user.email "[email protected]"
75+
git config --global user.name "oss-release-bot"
76+
'''
77+
78+
sh '''
79+
mvn release:prepare -B -DskipTests \
80+
-DautoVersionSubmodules=true \
81+
-DgenerateBackupPoms=false
82+
83+
git branch
84+
git log --pretty="format:%ce: %s" -8
85+
SCM_TAG=$(cat release.properties | grep scm.tag=)
86+
echo ${SCM_TAG#*=} > repo-release-tag.txt
87+
'''
88+
89+
script {
90+
env.REPO_RELEASE_TAG = sh(
91+
script: 'cat repo-release-tag.txt',
92+
returnStdout: true).trim()
93+
}
94+
echo "release tag: ${REPO_RELEASE_TAG}"
95+
}
96+
}
97+
98+
stage ('Release Maven Artifacts') {
99+
when {
100+
allOf {
101+
expression { params.PERFORM_MAVEN_RELEASE }
102+
branch 'master'
103+
}
104+
}
105+
106+
steps {
107+
echo "Update GitHub Repo"
108+
withCredentials([usernamePassword(
109+
credentialsId: "${GITHUB_OSS_TOKEN_ID}",
110+
passwordVariable: 'GIT_PASSWORD',
111+
usernameVariable: 'GIT_USERNAME')]) {
112+
sh '''
113+
git switch -c master
114+
git branch
115+
116+
git --no-pager log --since="60 days ago" --graph --pretty=format:'%C(auto)%h%d%Creset %C(cyan)(%cd)%Creset %C(green)%cn <%ce>%Creset %s'
117+
head -n 18 pom.xml
118+
ORIGIN="https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/prestodb/airbase.git"
119+
git push --follow-tags --set-upstream ${ORIGIN} master
120+
'''
121+
}
122+
123+
echo "Release ${REPO_RELEASE_TAG} maven artifacts"
124+
sh '''#!/bin/bash -ex
125+
export GPG_TTY=$TTY
126+
gpg --batch --import ${GPG_SECRET}
127+
echo ${GPG_TRUST} | gpg --import-ownertrust -
128+
gpg --list-secret-keys
129+
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
130+
printenv | sort
131+
132+
git checkout ${REPO_RELEASE_TAG}
133+
git status
134+
git branch
135+
git log -8
136+
head -n 18 pom.xml
137+
138+
mvn -s settings.xml -V -B -U -e -T2C deploy \
139+
-DautoReleaseAfterClose=true \
140+
-Dgpg.passphrase=${GPG_PASSPHRASE} \
141+
-DkeepStagingRepositoryOnCloseRuleFailure=true \
142+
-DkeepStagingRepositoryOnFailure=true \
143+
-DskipTests \
144+
-Poss-release \
145+
-Pdeploy-to-ossrh \
146+
-DstagingProgressTimeoutMinutes=10
147+
'''
148+
}
149+
}
150+
}
151+
}

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@
148148
<plugin>
149149
<groupId>org.apache.maven.plugins</groupId>
150150
<artifactId>maven-gpg-plugin</artifactId>
151+
<version>3.2.4</version>
152+
<configuration>
153+
<gpgArguments>
154+
<arg>--pinentry-mode</arg>
155+
<arg>loopback</arg>
156+
</gpgArguments>
157+
</configuration>
151158
</plugin>
152159
<!-- Use staging repository -->
153160
<plugin>

settings.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
4+
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6+
<servers>
7+
<server>
8+
<id>sonatype-nexus-snapshots</id>
9+
<username>${env.SONATYPE_NEXUS_USERNAME}</username>
10+
<password>${env.SONATYPE_NEXUS_PASSWORD}</password>
11+
</server>
12+
<server>
13+
<id>sonatype.snapshots</id>
14+
<username>${env.SONATYPE_NEXUS_USERNAME}</username>
15+
<password>${env.SONATYPE_NEXUS_PASSWORD}</password>
16+
</server>
17+
<server>
18+
<id>ossrh</id>
19+
<username>${env.SONATYPE_NEXUS_USERNAME}</username>
20+
<password>${env.SONATYPE_NEXUS_PASSWORD}</password>
21+
</server>
22+
</servers>
23+
<profiles>
24+
<profile>
25+
<id>nexus</id>
26+
<!--Enable snapshots for the built in central repo to direct -->
27+
<!--all requests to nexus via the mirror -->
28+
</profile>
29+
</profiles>
30+
<activeProfiles>
31+
<activeProfile>nexus</activeProfile>
32+
</activeProfiles>
33+
</settings>

0 commit comments

Comments
 (0)