Skip to content

Commit 7c01224

Browse files
committed
add release pipeline
1 parent 2a57170 commit 7c01224

File tree

3 files changed

+229
-0
lines changed

3 files changed

+229
-0
lines changed

Jenkinsfile

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

pom.xml

+42
Original file line numberDiff line numberDiff line change
@@ -516,4 +516,46 @@
516516
</dependency>
517517
</dependencies>
518518
</dependencyManagement>
519+
520+
<profiles>
521+
<profile>
522+
<id>oss-release</id>
523+
<properties>
524+
<!-- tests run in the preparation step of the release -->
525+
<skipTests>true</skipTests>
526+
</properties>
527+
<build>
528+
<plugins>
529+
<!-- oss requires a javadoc jar. Build one when releasing. -->
530+
<plugin>
531+
<groupId>org.apache.maven.plugins</groupId>
532+
<artifactId>maven-javadoc-plugin</artifactId>
533+
</plugin>
534+
<!-- Sign artifacts using gpg for oss upload -->
535+
<plugin>
536+
<groupId>org.apache.maven.plugins</groupId>
537+
<artifactId>maven-gpg-plugin</artifactId>
538+
<version>3.2.4</version>
539+
<configuration>
540+
<gpgArguments>
541+
<arg>--pinentry-mode</arg>
542+
<arg>loopback</arg>
543+
</gpgArguments>
544+
</configuration>
545+
</plugin>
546+
</plugins>
547+
</build>
548+
</profile>
549+
<profile>
550+
<id>deploy-to-ossrh</id>
551+
<build>
552+
<plugins>
553+
<plugin>
554+
<groupId>org.sonatype.plugins</groupId>
555+
<artifactId>nexus-staging-maven-plugin</artifactId>
556+
</plugin>
557+
</plugins>
558+
</build>
559+
</profile>
560+
</profiles>
519561
</project>

settings.xml

+33
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)