Add option to stage to Maven Central 18/12318/9
authorThanh Ha <thanh.ha@linuxfoundation.org>
Sat, 18 Aug 2018 16:26:15 +0000 (12:26 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 29 Oct 2018 20:37:30 +0000 (16:37 -0400)
Provide an option to also stage to OSSRH in preparation to release
to Maven Central.

In addition to printing the staging repo-id also print the URL to
the staging repo for convenience in stage-repo.txt.

Issue: RELENG-1398
Issue: https://jira.opendaylight.org/browse/RELENG-28
Change-Id: I0628cb5c7185e2143e448ceb4fa4752384581a5e
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
docs/jjb/lf-maven-jobs.rst
jjb/lf-maven-jobs.yaml
releasenotes/notes/maven-central-160a7cb5e538bfa8.yaml [new file with mode: 0644]
shell/create-netrc.sh
shell/maven-central.sh [new file with mode: 0644]
shell/maven-stage.sh

index 0e2215c..3a2a088 100644 (file)
@@ -92,6 +92,9 @@ Produces a CLM scan of the code into Nexus IQ Server.
     :build-timeout: Timeout in minutes before aborting build. (default: 60)
     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
     :java-version: Version of Java to use for the build. (default: openjdk8)
+    :mvn-central: Set to 'true' to also stage to OSSRH. This is for projects
+        that want to release to Maven Central. If set the parameter
+        ``ossrh-profile-id`` also needs to be set. (default: false)
     :mvn-global-settings: The name of the Maven global settings to use for
         Maven configuration. (default: global-settings)
     :mvn-opts: Sets MAVEN_OPTS. (default: '')
@@ -103,6 +106,8 @@ Produces a CLM scan of the code into Nexus IQ Server.
         For example 'odl-'. (default: '')
     :nexus-iq-stage: Stage the policy evaluation will be run against on
         the Nexus IQ Server. (default: 'build')
+    :ossrh-profile-id: Profile ID for project as provided by OSSRH.
+        (default: '')
     :stream: Keyword that can be used to represent a release code-name.
         Often the same as the branch. (default: master)
     :submodule-recursive: Whether to checkout submodules recursively.
index 16e93c5..dd67b60 100644 (file)
     git-url: '$GIT_URL/$PROJECT'
     github-url: 'https://github.com'
     java-version: openjdk8
+    mvn-central: false
     mvn-global-settings: global-settings
     mvn-goals: clean deploy
     mvn-opts: ''
     mvn-params: ''
     mvn-version: mvn35
+    ossrh-profile-id: ''
     sign-artifacts: false
     stream: master
     submodule-recursive: true
           sign-artifacts: '{sign-artifacts}'
           sign-dir: '$WORKSPACE/m2repo'
       - lf-maven-stage
+      - conditional-step:
+          condition-kind: boolean-expression
+          condition-expression: '{mvn-central}'
+          steps:
+            - lf-infra-create-netrc:
+                server-id: 'ossrh'
+            - inject:
+                properties-content: 'OSSRH_PROFILE_ID={ossrh-profile-id}'
+            - shell: !include-raw-escape: ../shell/maven-central.sh
       - lf-provide-maven-settings-cleanup
 
 - job-template:
diff --git a/releasenotes/notes/maven-central-160a7cb5e538bfa8.yaml b/releasenotes/notes/maven-central-160a7cb5e538bfa8.yaml
new file mode 100644 (file)
index 0000000..77f97de
--- /dev/null
@@ -0,0 +1,13 @@
+---
+features:
+  - |
+    Add support to maven-stage jobs to publish to Maven Central via OSSRH.
+
+    This is accomplished by adding these 2 new optional parameters to the job
+    configuration.
+
+    .. code-block:: yaml
+
+       - gerrit-maven-stage:
+           mvn-central: true
+           ossrh-profile-id: 7edbe315063867
index a123be8..57f1f15 100644 (file)
@@ -28,14 +28,23 @@ set -eu -o pipefail
 if [ -z "$CREDENTIAL" ] && [ "$SERVER_ID" == "logs" ]; then
     echo "WARN: Log server credential not found."
     exit 0
+elif [ -z "$CREDENTIAL" ] && [ "$SERVER_ID" == "ossrh" ]; then
+    echo "WARN: OSSRH credentials not found."
+    echo "      This is needed for staging to Maven Central."
+    exit 0
 elif [ -z "$CREDENTIAL" ]; then
     echo "ERROR: Credential not found."
     exit 1
 fi
 
-machine=$(echo "$NEXUS_URL" | awk -F/ '{print $3}')
+if [ "$SERVER_ID" == "ossrh" ]; then
+    machine="oss.sonatype.org"
+else
+    machine=$(echo "$NEXUS_URL" | awk -F/ '{print $3}')
+fi
+
 user=$(echo "$CREDENTIAL" | cut -f1 -d:)
 pass=$(echo "$CREDENTIAL" | cut -f2 -d:)
 
 set +x  # Disable `set -x` to prevent printing passwords
-echo "machine ${machine%:*} login $user password $pass" > ~/.netrc
+echo "machine ${machine%:*} login $user password $pass" >> ~/.netrc
diff --git a/shell/maven-central.sh b/shell/maven-central.sh
new file mode 100644 (file)
index 0000000..dede18d
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash -l
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+profile_id="${OSSRH_PROFILE_ID:-}"
+
+# Ensure we fail the job if any steps fail.
+set -eux -o pipefail
+
+MC_TMP_FILE="$(mktemp)"
+echo "Staging in OSSRH for Maven Central"
+lftools deploy nexus-stage "https://oss.sonatype.org" "$profile_id" "$WORKSPACE/m2repo" | tee "$MC_TMP_FILE"
+mc_staging_repo=$(sed -n -e 's/Staging repository \(.*\) created\./\1/p' "$MC_TMP_FILE")
+rm -f "$MC_TMP_FILE"
+
+echo "$mc_staging_repo https://oss.sonatype.org/content/repositories/$mc_staging_repo" | tee -a "$WORKSPACE/archives/staging-repo.txt"
index ea8652d..60949ac 100644 (file)
@@ -24,7 +24,7 @@ staging_repo=$(sed -n -e 's/Staging repository \(.*\) created\./\1/p' "$TMP_FILE
 
 # Store repo info to a file in archives
 mkdir -p "$WORKSPACE/archives"
-echo "$staging_repo" > "$WORKSPACE/archives/staging-repo.txt"
+echo "$staging_repo ${NEXUS_URL}/content/repositories/$staging_repo" | tee -a "$WORKSPACE/archives/staging-repo.txt"
 
 # Cleanup
 rm -f "$TMP_FILE"