Skip to content

Commit ffd0e7f

Browse files
Linsong WangLinsong Wang
authored andcommitted
add build and release pipeline
1 parent cea2b91 commit ffd0e7f

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed

Jenkinsfile

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

jenkins/agent.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
namespace: oss-agent
5+
spec:
6+
serviceAccountName: oss-agent
7+
containers:
8+
- name: maven
9+
image: maven:3.8.6-openjdk-8-slim
10+
tty: true
11+
resources:
12+
requests:
13+
memory: "1Gi"
14+
cpu: "500m"
15+
limits:
16+
memory: "2Gi"
17+
cpu: "1000m"
18+
command:
19+
- cat

jenkins/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)