From: Thanh Ha Date: Wed, 1 Nov 2017 18:28:03 +0000 (-0400) Subject: Add a snapshot mode to the deploy-nexus command X-Git-Tag: v0.11.0~4 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F7221%2F1;p=releng%2Flftools.git Add a snapshot mode to the deploy-nexus command This is necessary for RELENG-61 in order to allow pushing maven-metadata.xml files which in the case of release jobs should not be allowed. So add an option to the deploy-nexus command to allow an exception for snapshot artifacts. Issue: RELENG-173 Change-Id: I6f086bd0987502c5a967ab0b6f313ac405ceabc5 Signed-off-by: Thanh Ha --- diff --git a/lftools/cli/deploy.py b/lftools/cli/deploy.py index 209e963b..aad8eaef 100644 --- a/lftools/cli/deploy.py +++ b/lftools/cli/deploy.py @@ -149,8 +149,10 @@ def maven_file( @click.command() @click.argument('nexus-repo-url', envvar='NEXUS_REPO_URL') @click.argument('deploy-dir', envvar='DEPLOY_DIR') +@click.option('-s', '--snapshot', is_flag=True, default=False, + help='Deploy a snapshot repo.') @click.pass_context -def nexus(ctx, nexus_repo_url, deploy_dir): +def nexus(ctx, nexus_repo_url, deploy_dir, snapshot): """Deploy a Maven repository to a specified Nexus repository. This script takes a local Maven repository and deploys it to a Nexus @@ -160,7 +162,14 @@ def nexus(ctx, nexus_repo_url, deploy_dir): https://nexus.example.org/content/repositories/release """ - status = subprocess.call(['deploy', 'nexus', nexus_repo_url, deploy_dir]) + params = ['deploy', 'nexus'] + + if snapshot: + params.extend(["-s"]) + + params.extend([nexus_repo_url, deploy_dir]) + + status = subprocess.call(params) sys.exit(status) diff --git a/shell/deploy b/shell/deploy index 4fe12df9..e704d35b 100755 --- a/shell/deploy +++ b/shell/deploy @@ -508,6 +508,13 @@ deploy_maven_file () { fi } +deploy_nexus_usage() { + echo "Usage: deploy nexus " + echo + echo "Options:" + echo " -s # Enable snapshot mode for pushing snapshot artifacts to Nexus." +} + deploy_nexus() { # Deploy Maven artifacts to Nexus using curl # @@ -520,22 +527,49 @@ deploy_nexus() { # One purpose of this is so that we can get around the problematic # deploy-at-end configuration with upstream Maven. # https://issues.apache.org/jira/browse/MDEPLOY-193 + local snapshot="false" + + while getopts s o; do + case "$o" in + h) + deploy_nexus_usage + exit 0 + ;; + + s) + local snapshot="true" + ;; + + [?]) + deploy_nexus_usage + exit 1 + ;; + esac + done + shift $((OPTIND-1)) local nexus_repo_url="${1%/}" local deploy_dir="$2" if [ -z "$2" ]; then echo "Missing required arguments." - echo "Usage: deploy nexus " + deploy_nexus_usage exit 1 fi pushd "$deploy_dir" - file_list=($(find . -type f \ - ! -name "maven-metadata*" \ - ! -name _remote.repositories \ - ! -name resolver-status.properties \ - | cut -c 3-)) + if [ "$snapshot" == "true" ]; then + file_list=($(find . -type f \ + ! -name _remote.repositories \ + ! -name resolver-status.properties \ + | cut -c 3-)) + else + file_list=($(find . -type f \ + ! -name "maven-metadata*" \ + ! -name _remote.repositories \ + ! -name resolver-status.properties \ + | cut -c 3-)) + fi if hash parallel 2>/dev/null; then export -f upload_to_nexus