Skip to content

Commit 30dbe9b

Browse files
Add maven publish for 1.3.x release (opensearch-project#3507)
Signed-off-by: Prudhvi Godithi <pgodithi@amazon.com>
1 parent 1add5ea commit 30dbe9b

File tree

3 files changed

+239
-3
lines changed

3 files changed

+239
-3
lines changed

.codecov.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ codecov:
33
require_ci_to_pass: yes
44

55
coverage:
6-
precision: 2
7-
round: down
8-
range: '80...100'
6+
status:
7+
project:
8+
default:
9+
target: 80% # the required coverage value
10+
threshold: 2% # the leniency in hitting the target
911

1012
ignore:
1113
- '**/tests/*.py'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
lib = library(identifier: 'jenkins@1.5.4', retriever: modernSCM([
2+
$class: 'GitSCMSource',
3+
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
4+
]))
5+
6+
pipeline {
7+
options {
8+
timeout(time: 2, unit: 'HOURS')
9+
}
10+
agent none
11+
environment {
12+
AGENT_X64 = 'Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host'
13+
}
14+
triggers {
15+
parameterizedCron '''
16+
H/60 * * * * %INPUT_MANIFEST=1.3.10/opensearch-1.3.10.yml
17+
'''
18+
}
19+
parameters {
20+
string(
21+
name: 'COMPONENT_NAME',
22+
description: 'If this field contains one or more component names (e.g. OpenSearch common-utils ...), will build with "--component <COMPONENT_NAME> ...", else build everything in the INPUT_MANIFEST.',
23+
trim: true
24+
)
25+
string(
26+
name: 'INPUT_MANIFEST',
27+
description: 'Input manifest under the manifests folder, e.g. 2.0.0/opensearch-2.0.0.yml.',
28+
trim: true
29+
)
30+
}
31+
stages {
32+
stage('dockerAgent-setup') {
33+
agent {
34+
docker {
35+
label AGENT_X64
36+
image 'docker/library/alpine:3'
37+
registryUrl 'https://public.ecr.aws/'
38+
alwaysPull true
39+
}
40+
}
41+
steps {
42+
script {
43+
echo("Detect Docker Images and Related Parameters")
44+
dockerAgent = detectDockerAgent()
45+
currentBuild.description = INPUT_MANIFEST
46+
}
47+
}
48+
}
49+
stage('publish-maven-snaphots') {
50+
environment {
51+
SNAPSHOT_REPO_URL = "https://aws.oss.sonatype.org/content/repositories/snapshots/"
52+
}
53+
agent {
54+
docker {
55+
label AGENT_X64
56+
image dockerAgent.image
57+
args dockerAgent.args
58+
alwaysPull true
59+
}
60+
}
61+
steps {
62+
script {
63+
buildManifest(
64+
componentName: "${COMPONENT_NAME}",
65+
inputManifest: "manifests/${INPUT_MANIFEST}",
66+
platform: 'linux',
67+
architecture: 'x64',
68+
distribution: 'tar',
69+
snapshot: true
70+
)
71+
72+
String mavenPath = "$WORKSPACE/tar/builds/opensearch/maven"
73+
74+
if (fileExists(mavenPath)) {
75+
withCredentials([
76+
string(credentialsId: 'maven-snapshots-username', variable: 'SONATYPE_USERNAME'),
77+
string(credentialsId: 'maven-snapshots-password', variable: 'SONATYPE_PASSWORD')
78+
]) {
79+
sh("$WORKSPACE/publish/publish-snapshot.sh ${mavenPath}")
80+
}
81+
} else {
82+
echo "Skipping publishing snapshots, ${mavenPath} does not exist."
83+
}
84+
}
85+
}
86+
post {
87+
always {
88+
postCleanup()
89+
}
90+
}
91+
}
92+
}
93+
}

publish/publish-snapshot.sh

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/bash
2+
3+
# Copyright OpenSearch Contributors
4+
###### Information ############################################################################
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# The OpenSearch Contributors require contributions made to
8+
# this file be licensed under the Apache-2.0 license or a
9+
# compatible open source license.
10+
#
11+
# Name: publish-snapshot.sh
12+
# Language: Shell
13+
#
14+
# About: Deploy opensearch artifacts to a sonatype snapshot repository.
15+
# This script will search POM files under the passed in directory and publish artifacts to
16+
# a snapshot repository using the mvn deploy plugin.
17+
#
18+
# Usage: ./publish-snapshot.sh <directory>
19+
#
20+
###############################################################################################
21+
set -e
22+
23+
[ -z "${1:-}" ] && {
24+
usage
25+
}
26+
27+
usage() {
28+
echo "usage: $0 [-h] [dir]"
29+
echo " dir parent directory of artifacts to be published to org/opensearch namespace."
30+
echo " example: dir = ~/.m2/repository/org/opensearch where dir contains artifacts of a path:"
31+
echo " /maven/reindex-client/1.0.0-SNAPSHOT/reindex-client-1.0.0-SNAPSHOT.jar"
32+
echo " -h display help"
33+
echo "Required environment variables:"
34+
echo "SONATYPE_USERNAME - username with publish rights to a sonatype repository"
35+
echo "SONATYPE_PASSWORD - password for sonatype"
36+
echo "SNAPSHOT_REPO_URL - repository URL ex. http://localhost:8081/nexus/content/repositories/snapshots/"
37+
exit 1
38+
}
39+
40+
while getopts ":h" option; do
41+
case $option in
42+
h)
43+
usage
44+
;;
45+
\?)
46+
echo "Invalid option -$OPTARG" >&2
47+
usage
48+
;;
49+
esac
50+
done
51+
52+
[ -z "${SONATYPE_USERNAME}" ] && {
53+
echo "SONATYPE_USERNAME is required"
54+
exit 1
55+
}
56+
57+
[ -z "${SONATYPE_PASSWORD}" ] && {
58+
echo "SONATYPE_PASSWORD is required"
59+
exit 1
60+
}
61+
62+
[ -z "${SNAPSHOT_REPO_URL}" ] && {
63+
echo "REPO_URL is required"
64+
exit 1
65+
}
66+
67+
if [ ! -d "$1" ]; then
68+
echo "Invalid directory $1 does not exist"
69+
usage
70+
fi
71+
72+
create_maven_settings() {
73+
# Create a settings.xml file with the user+password for maven
74+
mvn_settings="${workdir}/mvn-settings.xml"
75+
cat >${mvn_settings} <<-EOF
76+
<?xml version="1.0" encoding="UTF-8" ?>
77+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
78+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
79+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
80+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
81+
<servers>
82+
<server>
83+
<id>nexus</id>
84+
<username>${SONATYPE_USERNAME}</username>
85+
<password>${SONATYPE_PASSWORD}</password>
86+
</server>
87+
</servers>
88+
</settings>
89+
EOF
90+
}
91+
92+
url="${SNAPSHOT_REPO_URL}"
93+
workdir=$(mktemp -d)
94+
95+
function cleanup() {
96+
rm -rf "${workdir}"
97+
}
98+
99+
trap cleanup TERM INT EXIT
100+
101+
create_maven_settings
102+
103+
cd "$1"
104+
105+
echo "searching for poms under $PWD"
106+
107+
pomFiles="$(find "." -name '*.pom')"
108+
if [ -z "${pomFiles}" ]; then
109+
echo "No artifacts found under $PWD"
110+
exit 1
111+
fi
112+
113+
for pom in ${pomFiles}; do
114+
pom_dir="$(dirname "${pom}")"
115+
for FILE in "${pom_dir}"/*; do
116+
# The POM is deployed with the artifact in a single deploy-file command, we can skip over it
117+
if [[ $FILE != $pom ]] &&
118+
[[ $FILE != *"test-fixtures"* ]] && # This is a hack to ensure the OpenSearch build-tools test fixture jar is not uploaded instead of the actual build-tools jar.
119+
[[ $FILE != *"javadoc"* ]] &&
120+
[[ $FILE != *"sources"* ]]; then
121+
extension="${FILE##*.}"
122+
case $extension in jar | war | zip)
123+
echo "Uploading: ${FILE} with ${pom} to ${url}"
124+
mvn --settings="${mvn_settings}" deploy:deploy-file \
125+
-DgeneratePom=false \
126+
-DrepositoryId=nexus \
127+
-Durl="${SNAPSHOT_REPO_URL}" \
128+
-DpomFile="${pom}" \
129+
-Dfile="${FILE}" || echo "Failed to upload ${FILE}"
130+
;;
131+
*) echo "Skipping upload for ${FILE}" ;;
132+
esac
133+
fi
134+
done
135+
136+
echo "Finished uploading ${pom_dir}"
137+
done
138+
139+
echo "==========================================="
140+
echo "Done."
141+
echo "==========================================="

0 commit comments

Comments
 (0)