From: Thanh Ha Date: Sat, 18 Aug 2018 16:26:15 +0000 (-0400) Subject: Add option to stage to Maven Central X-Git-Tag: v0.26.1^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=5d1ddb578a5253fc360a73be6ceea89d65af043e;p=releng%2Fglobal-jjb.git Add option to stage to Maven Central 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 --- diff --git a/docs/jjb/lf-maven-jobs.rst b/docs/jjb/lf-maven-jobs.rst index 494d32d0..fd7fc26b 100644 --- a/docs/jjb/lf-maven-jobs.rst +++ b/docs/jjb/lf-maven-jobs.rst @@ -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. diff --git a/jjb/lf-maven-jobs.yaml b/jjb/lf-maven-jobs.yaml index c5fffb77..b80c5a56 100644 --- a/jjb/lf-maven-jobs.yaml +++ b/jjb/lf-maven-jobs.yaml @@ -655,11 +655,13 @@ 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 @@ -713,6 +715,15 @@ 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 index 00000000..77f97de9 --- /dev/null +++ b/releasenotes/notes/maven-central-160a7cb5e538bfa8.yaml @@ -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 diff --git a/shell/create-netrc.sh b/shell/create-netrc.sh index a123be8d..57f1f15c 100644 --- a/shell/create-netrc.sh +++ b/shell/create-netrc.sh @@ -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 index 00000000..dede18d4 --- /dev/null +++ b/shell/maven-central.sh @@ -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" diff --git a/shell/maven-stage.sh b/shell/maven-stage.sh index ea8652dc..60949ace 100644 --- a/shell/maven-stage.sh +++ b/shell/maven-stage.sh @@ -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"