From: Thanh Ha Date: Fri, 9 Jun 2017 03:12:56 +0000 (-0400) Subject: Add deploy nexus-stage command X-Git-Tag: v0.3.0~1 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=3c498dc;p=releng%2Flftools.git Add deploy nexus-stage command Use curl to deploy a staging repository to Nexus. Jira: RELENG-120 Change-Id: Ibd6c25f4318264e5f3e96aeede1c7fe891c473b2 Signed-off-by: Thanh Ha --- diff --git a/docs/commands/deploy.rst b/docs/commands/deploy.rst index 0f7a2a4c..697b12e7 100644 --- a/docs/commands/deploy.rst +++ b/docs/commands/deploy.rst @@ -24,3 +24,8 @@ nexus ----- .. program-output:: lftools deploy nexus --help + +nexus-stage +----- + +.. program-output:: lftools deploy nexus-stage --help diff --git a/lftools/cli/deploy.py b/lftools/cli/deploy.py index 67057aa0..5bf3a909 100644 --- a/lftools/cli/deploy.py +++ b/lftools/cli/deploy.py @@ -85,6 +85,22 @@ def nexus(ctx, nexus_repo_url, deploy_dir): sys.exit(status) +@click.command(name='nexus-stage') +@click.argument('nexus-url', envvar='NEXUS_URL') +@click.argument('staging-profile-id', envvar='STAGING_PROFILE_ID') +@click.argument('deploy-dir', envvar='DEPLOY_DIR') +@click.pass_context +def nexus_stage(ctx, nexus_url, staging_profile_id, deploy_dir): + """Deploy a Maven repository to a Nexus staging repository. + + This script takes a local Maven repository and deploys it to a Nexus + staging repository as defined by the staging-profile-id. + """ + status = subprocess.call(['deploy', 'nexus-stage', nexus_url, staging_profile_id, deploy_dir]) + sys.exit(status) + + deploy.add_command(archives) deploy.add_command(logs) deploy.add_command(nexus) +deploy.add_command(nexus_stage) diff --git a/shell/deploy b/shell/deploy index 1b363165..20dc09bc 100755 --- a/shell/deploy +++ b/shell/deploy @@ -286,6 +286,76 @@ deploy_nexus() { popd } +deploy_nexus_stage() { + # Deploy Maven artifacts to Nexus staging repo using curl + # + # Parameters: + # nexus_url: URL to Nexus server. (Ex: https://nexus.opendaylight.org) + # staging_profile_id: The staging profile id as defined in Nexus for the + # staging repo. + # deploy_dir: The directory to deploy. (Ex: /tmp/m2repo) + + local nexus_url="$1" + local staging_profile_id="$2" + local deploy_dir="$3" + + if [ -z "$3" ]; then + echo "Missing required arguments." + echo "Usage: deploy nexus-stage " + exit 1 + fi + + FILE_XML="$(mktemp)" + + cat > "$FILE_XML" < + + Create staging repo. + + +EOF + + local resp + local status + resp=$(curl -s -w "%{http_code}" --netrc -X POST -d "@$FILE_XML" \ + -H "Content-Type:application/xml" \ + "${nexus_url}/service/local/staging/profiles/${staging_profile_id}/start") + status=$(echo "$resp" | awk 'END {print $NF}') + + if echo "$resp" | grep -q nexus-error; then + local msg + msg=$(sed -n -e 's/.*\(.*\)<\/msg>.*/\1/p' <<< $resp) + echo "ERROR: $msg" + exit "$status" + fi + + local staging_repo_id + staging_repo_id=$(sed -n -e 's/.*\(.*\)<\/stagedRepositoryId>.*/\1/p' <<< $resp) + echo "Staging repository $staging_repo_id created." + + deploy_nexus "${nexus_url}/service/local/staging/deployByRepositoryId/${staging_repo_id}" "${deploy_dir}" + + # Close the repo + + cat > "$FILE_XML" < + + $staging_repo_id + Close staging repository. + + +EOF + + curl -s --netrc -X POST \ + -H "Content-Type:application/xml" -d "@$FILE_XML" \ + "${nexus_url}/service/local/staging/profiles/${staging_profile_id}/finish" + + echo "Completed uploading files to ${staging_repo_id}." + + # cleanup + rm "$FILE_XML" +} + # Only run the script if it is being called directly and not sourced. if [[ "${BASH_SOURCE[0]}" == "${0}" ]] then